最近在研究android自動化測試,爲了減小log日誌,每次循環執行之後清空日誌,在循環體中使用線程,如下:
new Thread(new Runnable() {
@Override
public void run() {
while (!Thread.currentThread().isInterrupted()) {
Process p1 = null;
String cmd = "adb logcat -v time > D:\\test.txt";
try {
p1 = Runtime.getRuntime().exec(cmd);
p1.waitFor();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
).start();
Thread.interrupt();
結果發現線程沒有起到作用,不知道問題出在哪兒。。。有知道的大神求指導~
最後直接使用進程的中斷來達到目標
String cmd = "adb logcat -v time > D:\\test.txt";
Process pro = Runtime.getRuntime().exec(cmd); pro.waitFor(); //測試步驟
//清空文件 pro.destory();