我正在尝试从Java代码中执行外部命令,但我注意到在使用 Runtime.getRuntime().exec(...)
和 new ProcessBuilder(...).start()
时存在差异。
当使用 Runtime
时:
Process p = Runtime.getRuntime().exec(installation_path +
uninstall_path +
uninstall_command +
uninstall_arguments);
p.waitFor();
退出值为0,命令正常终止。
然而,使用ProcessBuilder
:
Process p = (new ProcessBuilder(installation_path +
uninstall_path +
uninstall_command,
uninstall_arguments)).start();
p.waitFor();
退出值为1001并且命令在中途终止,尽管 waitFor
返回。
我该如何修复 ProcessBuilder
的问题?
cmd.exe
的提及。 - Luke WoodwardString.split("\\s+")
:-) - Stephen C