【发布时间】:2014-04-30 08:15:31
【问题描述】:
当尝试从 Java 调用在普通命令行中正确执行的 git 命令时,我得到一个奇怪的结果:它什么也不输出。
例如,如果我尝试运行这个:
public class GitTest {
public static void main(String args[]) throws IOException{
String command = "git clone http://git-wip-us.apache.org/repos/asf/accumulo.git";
Process p = Runtime.getRuntime().exec(command);
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
String text = command + "\n";
System.out.println(text);
while ((line = input.readLine()) != null) {
text += line;
System.out.println("Line: " + line);
}
}
}
我没有得到任何输出(除了之前打印的命令)。似乎 git 仍在下载某些东西,但没有告诉我。也许它会在完成后输出所有内容(因此正常的 git 调用输出,准备了多少,并且每次都更改此行 - 可能正因为如此 BufferedReader 无法读取完成的行,因此不输出它)。
有什么变通方法可以让它工作吗?
【问题讨论】: