让应用程序在自己的目录中运行
我正在尝试让一个应用程序(游戏)以 Java 脚本启动。 背后有一个很长的解释,所以我将跳过这一部分。
除非从自己的目录执行,否则游戏不会运行,IE:仅告诉 Java 启动 EXE 就会在游戏中出现错误。 它必须从其目录启动。
我已经在谷歌上搜索了几个小时,似乎找不到任何真正的答案。 经过大量谷歌搜索后,我了解到这应该是正确的:
String workingDir = "F:\\Games\\COD4\\";
String cmd = "iw3mp.exe";
Runtime.getRuntime().exec(cmd,null,new File(workingDir));
但是,我收到此错误:
Exception in thread "main" java.io.IOException: Cannot run program "iw3mp.exe" (in directory "F:\Games\COD4"): CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at cod4launcher.main(cod4launcher.java:29)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 4 more
请帮忙! 谢谢。
I'm trying to get an application (a game) to start with a Java script. There is a long explanation behind why, so I'll skip that part.
The game won't run unless it is executed from its own directory, IE: Just telling Java to launch the EXE gives errors within the game. It must be launched from its directory.
I've Googled for hours over this and can't seem to find any real answers. After a lot of Googleing, I've learned this should be right:
String workingDir = "F:\\Games\\COD4\\";
String cmd = "iw3mp.exe";
Runtime.getRuntime().exec(cmd,null,new File(workingDir));
However, I get this error:
Exception in thread "main" java.io.IOException: Cannot run program "iw3mp.exe" (in directory "F:\Games\COD4"): CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at cod4launcher.main(cod4launcher.java:29)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 4 more
Please help! Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请尝试以下操作:
iw3mp.exe 可能不在您的系统路径上,因此您必须为 Java 提供可执行文件的绝对路径。
Try this instead:
iw3mp.exe probably isn't on your system path so you have to give Java an absolute path to the executable.
使用
java.lang.ProcessBuilder#directory(java.io.File)
Use
java.lang.ProcessBuilder#directory(java.io.File)