Java ProcessBuilder执行命令没有输出

时间:2016-09-09 07:18:43

标签: java command-line processbuilder

我正在使用ProcessBuilder在我的java应用程序中执行git命令。当命令是“git status”或“git branch”时输出字符串是正确的,但是当命令是“git clone”时输出为空。我想知道如何获得“git clone”的输出字符串。提前谢谢。

try {
    ProcessBuilder pb = new ProcessBuilder("git", "clone", "address");
    Process pr = pb.start();
    BufferedReader buf = new BufferReader(new InputStreamReader(pr.getInputStream()));
    String cmdLine = "";
    while ((cmdLine = buf.readLine()) != null) {
        System.out.println(cmdLine);
    }
} catch (Exception e) {

}

0 个答案:

没有答案