使用Java捕获命令行输出

时间:2014-07-11 15:57:46

标签: java process outputstream

Process process = Runtime.getRuntime().exec("C:/chess/h.exe");
Scanner scanner = new Scanner(process.getInputStream());
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));
writer.write("uci");
while (true) System.out.println(scanner.nextLine());

它写道:

 Houdini 4 Pro x64 (c) 2013 Robert Houdart

 info string 4 processor(s) found info string NUMA configuration with 1
 node(s), offset 0 info string 128 MB Hash

如果我在控制台中执行相同操作,则结果为enter image description here

其他文字在哪里消失了?如何使用我的程序看到它?

1 个答案:

答案 0 :(得分:1)

尝试捕获错误输出,可能是h.exe程序只将“info”消息打印到标准输出,其他所有内容都发送到错误输出。

process.getErrorStream();