why process give null inputstream in test runner class?

293 views Asked by At

In my android test project, I simply read the logcat using adb command

like,

public StringBuilder log=new StringBuilder();
    public String line="";
    public String temp="";

public void testSolo() throws Exception {

             String baseCommand = "logcat -v time";
            baseCommand += " ActivityManager:I "; // Info for my app
            baseCommand += " *:S "; // Silence others

            try {
                  Process logReaderProcess = Runtime.getRuntime().exec(baseCommand);
                  BufferedReader bufferedReader = new BufferedReader(
                   new InputStreamReader(logReaderProcess.getInputStream()));

                   while ((line =bufferedReader.readLine()) != null) {
                            log.append(line); // here readLine() returns null
                          }

            }
            catch (IOException e1) {
                      // TODO Auto-generated catch block
                      e1.printStackTrace();
                    }

 }

but, here in string line I always get null value,

while the same thing always run in the android activity's onCreate() . I don't understand why this happen?

Same thing runs in activity class and not in the android test project.

I also add use -permission for READ_LOGS and WRITE_EXTERNAL_STORAGE in test project's manifest.xml file.

Is there anybody knows how it works or what happens?

Thanks in advance.

2

There are 2 answers

1
savemaxim On

Try to add

    <uses-permission android:name="android.permission.READ_LOGS" />

to your manifest.

0
jazz On
String []baseCommand = new String[]{"logcat", "-v","time"}; 
Process logReaderProcess = Runtime.getRuntime().exec(baseCommand);

try this out