我需要找到在 Mac 上安装 Firefox 应用程序的目录,为此我运行终端命令:
find / -name Firefox.app 2>/dev/null
现在我需要在 java 程序中运行相同的命令,我的代码是:
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class kill{
public static void main(String[] args) throws Exception{
String cmds[] = {"find","/","-name","Firefox.app"};
Process p = Runtime.getRuntime().exec(cmds);
p.waitFor();
//int exitVal = p.waitFor();
//System.out.println("Process exitValue:" + exitVal);
BufferedReader reader =
new BufferedReader(new InputStreamReader(
p.getInputStream()));
String line = reader.readLine();
while (line != null) {
line = reader.readLine();
System.out.println(line);
}
}
}
但它并没有返回我的路径。谁能告诉我这里出了什么问题..任何帮助将不胜感激