尝试从Java中调用一个在正常命令行中正确执行的git命令时,我得到了一个奇怪的结果:没有任何输出。
例如,如果我尝试运行以下命令:
我没有任何输出(除了命令,在之前打印)。似乎git仍在下载某些内容,但没有告诉我。也许它会在完成后输出所有内容(所以正常的git调用会输出多少已经准备好,每次更改这一行 - 也许因为这个BufferedReader无法读取完成的行,因此无法输出它)。有没有办法解决这个问题?
例如,如果我尝试运行以下命令:
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无法读取完成的行,因此无法输出它)。有没有办法解决这个问题?