如果proc已退出,输出字符串存储在哪里?
内部缓冲区?
如果内部缓冲区太小而不能包含巨大的字符串?
我们可以保证不会丢失字符串吗?
package Hello;
import java.io.*;
public class Hello {
public static void main(String args[]) {
String line = null;
try {
ProcessBuilder pb = new
ProcessBuilder("command_to_output_huge_strings");
Process proc = pb.start();
proc.waitFor();
//
// Now proc may have finished its huge output and exited.
//
// Now we want to get the huge strings proc outputed.
BufferedReader stdInput = new BufferedReader(
new InputStreamReader(proc.getInputStream()));
while ((line = stdInput.readLine()) != null) {
System.out.println(line);
}
} catch (Exception e) {
}
}
}
答案 0 :(得分:1)
Process.getInputStream().
Process.waitFor()
,然后尝试读取其输出。waitFor().