我正在开发应用程序来过滤由 android 生成的 logcat。我使用 getruntme.exec 执行了 linux 命令和“/system/bin/logcat -b main -f/sdcard/logcat.txt”。执行命令,但它在单独的进程中运行,尽管我卸载了我的应用程序,进程继续运行。有什么方法可以阻止在另一个进程中运行。
最佳答案
getruntme.exec,你的意思是你正在使用这样的东西吗? (借自 here ):
import java.io.*;
public class TestExec {
public static void main(String[] args) {
try {
Process p = Runtime.getRuntime().exec("cmd /C dir");
BufferedReader in = new BufferedReader(
new InputStreamReader(p.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
然后你可以用 p.destroy() 杀死它
关于android - 如何防止在单独的进程中在 java 中执行 Linux 命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9000324/