Java运行时exec()在错误流中打印

时间:2016-01-21 13:41:38

标签: java shell

为什么这样:

Runtime rt = Runtime.getRuntime();
String cmd = "cmd /c java -version";
Process process = rt.exec(cmd);
process.waitFor();

StringBuffer output = new StringBuffer();
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getErrorStream()));

String line;           
while ((line = reader.readLine())!= null) {
    output.append(line + "\n");
} 
System.out.println(output);
} catch (Exception e) {
    logger.error(e);
}

打印到错误流而不是标准输入流?命令java -version的错误是什么?

N.B。 cmd /c是因为我在Windows机器上

0 个答案:

没有答案