0

I use the following code to read the logcat in Android.

Process process = Runtime.getRuntime().exec("logcat -v time");

Since the logcat file size is large, I have to filter the logcat messages. So I used the following code to filter logcat.

Process process = Runtime.getRuntime().exec("logcat -v time | grep -v -E \"(libloc|RPC)\"");

where (libloc|RPC) are tags.

But Grep code is not working in Android. Can anyone please help me with this?

PgmFreek
  • 6,374
  • 3
  • 36
  • 47

2 Answers2

1

If grep is not working (I use regexp on the logcat UI directly) then you can make your own grep reading line by line.

Process process = Runtime.getRuntime().exec("logcat -v time");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));

while ((line = bufferedReader.readLine()) != null) {
  if(line.matches("^.*(libloc|RPC).*$")) {
     //code
  }
}

Reference

Community
  • 1
  • 1
AlexBcn
  • 2,450
  • 2
  • 17
  • 28
-1

I got the answer. I have to use the file name to use the grep command.

Runtime.getRuntime().exec("logcat -v time -f "+logCatFile.getAbsolutePath()+ " libloc:S RPC:S")
PgmFreek
  • 6,374
  • 3
  • 36
  • 47