Shell命令不适用于Java执行
我使用以下方法执行shell命令:Shell命令不适用于Java执行,java,Java,我使用以下方法执行shell命令: private String executeShellCommand(String command) { StringBuffer output = new StringBuffer(); Process p; try { p = Runtime.getRuntime().exec(command); p.waitFor(); Buffe
private String executeShellCommand(String command) {
StringBuffer output = new StringBuffer();
Process p;
try {
p = Runtime.getRuntime().exec(command);
p.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
while ((line = reader.readLine())!= null) {
output.append(line + "\n");
}
} catch (Exception e) {
e.printStackTrace();
}
return output.toString();
}
除此之外,这适用于大多数命令:
executeShellCommandbrew安装libimobiledevice
它可以在Mac终端上正常工作,但在这里不行
我得到了这个错误:
无法运行程序brew:error=2,没有此类文件或目录您可以通过以下方式安装brew:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew不在路径上。将其添加到路径中,或者将完整路径放入brew,例如/usr/bin/brewOr如果它确实是只有shell才知道的内容,例如shell函数,那么您应该首先启动shell,例如/bin/bash……我尝试从完整路径调用它,但它返回了相同的错误。如何启动shell,然后运行@JonSkeet命令?ThanksHow您知道brew未安装吗?可能路径未配置为包含brew?brew已安装。我猜由于某种原因,该命令无法识别。