我想打印echo %path%
fromJava
而不是cmd
.
我有以下代码:
private void getPath() throws IOException {
String getPath = "cmd.exe /C echo %path%";
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(getPath);
BufferedReader reader = new BufferedReader(new InputStreamReader(proc.getInputStream()));
String commandOutput = "";
while (commandOutput != null) {
commandOutput = reader.readLine();
System.out.println(commandOutput);
}
}
如果我echo %path%
从cmd
输出开始运行:
C:\Oracle\Ora11\bin;C:\Oracle\Ora10\bin;C:\Program Files\Common
但是Java
程序的输出开始于:
C:/Program Files/Java/jre7/bin/client;C:/Program Files/Java/jre7/bin;C:/Program Files/Java/jre7/lib/i386
并且只有在这一行之后,其余的输出是相似的。
为什么会这样?