Java Runtime.exec(COMMAND) 在 win2K8 R2 中不起作用
我正在使用以下两行创建一个进程
Runtime rt = Runtime.getRuntime();
Process p = rt.exec(COMMAND);
,其中 COMMAND = "program.exe"
。 program.exe
位于系统的 PATH 变量中。
现在的问题是,这仅在 Windows 2K8 R2 中不起作用。它在所有其他版本的 Windows(winXP、win2003)上都能正常工作,
报告的错误是:
java.io.IOException: Cannot run program "program.exe": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(Unknown Source)
I am creating a process using the below 2 lines
Runtime rt = Runtime.getRuntime();
Process p = rt.exec(COMMAND);
where COMMAND = "program.exe"
. program.exe
is on the system's PATH variable.
Now the problem is that this does not work only in Windows 2K8 R2. It works fine on every other flavour of windows (winXP, win2003)
The error reported is :
java.io.IOException: Cannot run program "program.exe": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(Unknown Source)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以从命令行手动运行该程序。您可以使用完整路径规范从父进程中运行该程序。我想说我们可以假设程序运行正常。
还有什么不同?也许父进程运行的环境?我会在启动进程之前检查路径。您正在使用Java。太多 Java程序使用批处理文件来启动 JVM 进程。该批处理文件可能会破坏 PATH 变量。
如果这是您的程序并且不涉及批处理文件,我将在您运行父程序时检查当前工作目录。它也可能影响运行时发现的内容。
You can run the program manually from the command line. You can run the program from within the parent process using the full path specification. I would say we can assume the program runs properly.
What else could be different? The environment the parent process is running under perhaps? I would check the PATH before launching the process. You are using Java. Too many Java programs use batch files to launch the JVM process. This batch file could be mucking with the PATH variable.
If this is your program and no batch file in involved I would check the current working directory when you run the parent program. It could affect what gets found at runtime as well.