Shell命令不适用于Java执行

时间:2015-03-30 14:12:11

标签: java

我使用以下方法执行shell命令:

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();

    }

这适用于除此之外的大多数命令:

executeShellCommand("brew install libimobiledevice");

它可以在Mac终端上正常工作但不在这里。

我收到此错误:

Cannot run program "brew": error=2, No such file or directory

1 个答案:

答案 0 :(得分:0)

您可以通过以下方式安装brew:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"