我查的资料以下的代码可以从程序中读出logcat 的输出信息。然而,当我调用这个函数时,并没起作用,从system.out中除了输出"logcat called"以外,再没有输出别的任何信息。资料中说的这段代码没错,但是现在实现不了。
public void Collector_logcat(){
String stringbuffer="";
String command="logcat -d";
String command_c="logcat -c";
System.out.println("logcat called\n");
try{
m_logcatprocess=Runtime.getRuntime().exec(command);
m_logcat_inputreader=new InputStreamReader(m_logcatprocess.getInputStream());
m_logcat_reader=new BufferedReader(m_logcat_inputreader);
while((stringbuffer=m_logcat_reader.readLine())!=null){
System.out.println(stringbuffer+"\n");
}
Runtime.getRuntime().exec(command_c);
}
catch(Exception ex){
System.out.println(ex.getMessage());
System.out.println("error in Collector_logcat\n");
}
return ;
}