为什么这样:
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机器上