我必须在Mac OS上执行一条命令:
killall -KILL "Google Chrome"当我在终端中执行它,或者用这个命令运行一个.command文件时,它就能工作。
我在Java代码中尝试了所有这些
Runtime.getRuntime().exec("/usr/bin/killall -KILL \"Google Chrome\"");
Runtime.getRuntime().exec("killall -KILL \"Google Chrome\"");
Runtime.getRuntime().exec("/bin/bash -c \"killall -KILL \\\"Google Chrome\\\"\"");
Runtime.getRuntime().exec("bash -c \"killall -KILL \\\"Google Chrome\\\"\"");
Runtime.getRuntime().exec("/usr/bin/killall", new String[]{"-KILL", "Google Chrome"});
Runtime.getRuntime().exec("killall", new String[]{"-KILL", "Google Chrome"});
Runtime.getRuntime().exec("/bin/bash", new String[]{"-c", "killall -KILL \"Google Chrome\""});
Runtime.getRuntime().exec("bash", new String[]{"-c", "killall -KILL \"Google Chrome\""});但它不起作用。
可能的问题是什么?
发布于 2014-01-30 23:43:31
这就是你要的。
String cmds[] = {"killall","Google Chrome"};
Runtime.getRuntime().exec(cmds);发布于 2014-01-30 23:44:01
你可以试试这个:
String[] command = { "/usr/bin/killall", "-KILL", "Google Chrome" };
Runtime.getRuntime().exec(command);您也可以尝试上述操作,方法是向Google Chrome添加引号,如下所示:
String[] command = { "/usr/bin/killall", "-KILL","\"Google Chrome\"" };https://stackoverflow.com/questions/21460745
复制相似问题