程序完成运行后,将COMMAND输出保存到文本文件

时间:2014-08-10 10:03:45

标签: java windows cmd command volatility

程序运行完毕后,有没有办法将命令提示符的最终输出保存到文本文件中?我用ProcessBuilder尝试过它并没有用。 (原因是因为我的输出没有立即出现,它在输出加载到命令提示符屏幕之前经过了一段很短的处理时间)。

String command = "cmd /c start cmd /k E:\\vol231.exe -f E:\\KOHMOHOJOJO-PC-20140714-152414.raw imageinfo > output.txt";
Process p = Runtime.getRuntime().exec(command);

enter image description here enter image description here

它实际上需要大约2-5分钟来处理。

我提到了几个网站,但它仍然无效。任何给予的帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

您可以尝试使用java代码保存输出:

StringWriter writer = new StringWriter();
IOUtils.copy(p.getInputStream(), writer, encoding);
String theString = writer.toString();

还可以使用类" ProcessBuilder"

保存错误流
相关问题