2013-07-03 115 views
0

我使用以下代碼讀取Android中的logcat。使用GREP命令在Android中過濾logcat

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

由於logcat文件的大小很大,我必須過濾logcat消息。所以我用下面的代碼來過濾logcat。

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

其中(libloc | RPC)是標籤。

但是,Grep代碼在Android中不起作用。任何人都可以幫助我嗎?

回答

0

我得到了答案。我必須使用文件名來使用grep命令。

Runtime.getRuntime().exec("logcat -v time -f "+logCatFile.getAbsolutePath()+ " libloc:S RPC:S") 
+0

其中是grep命令? – hackjutsu

1

如果grep不能正常工作(我直接在logcat UI上使用regexp),那麼你可以一行一行地自己讀取grep。

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