【发布时间】:2020-08-19 21:59:12
【问题描述】:
看起来很简单。
我正在使用Runtime.getRuntime().exec(commandString);
我试过了
String commandString = "logcat -v raw --pid=" + PID);
Runtime.getRuntime().exec(commandString);
我已经在没有-v raw 的情况下进行了尝试,并且还尝试(并且需要)使用| 来使用多个PID。
似乎没有任何效果。我有一个new BufferedReader(new InputStreamReader(p.getInputStream())); 什么也得不到。如果我不对 PID 进行过滤,它可以工作,但会打印出所有命中 logcat 的东西,这不是很有用。
我错过了什么?
这是重要部分的全部内容。
try {
Runtime.getRuntime().exec("logcat -c").waitFor();
StringBuilder pids = new StringBuilder("");
for (int i = 0; i < PIDs.size(); i++){
pids.append(Integer.toString(PIDs.get(i)));
if (i < PIDs.size() - 1){
pids.append("|");
}
}
String commmandString = "logcat -v raw --pid=" + pids);
p = Runtime.getRuntime().exec(commmandString);
mBufferedReader = new BufferedReader(new InputStreamReader(p.getInputStream()));
} catch (IOException e) {} catch (InterruptedException e) {}
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
p.destroy();
};
});
mThreadAlive = true;
mLoggingThread.start();
【问题讨论】: