tags:

views:

697

answers:

2

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.

+4  A: 

Try this instead:

String workingDir = "F:\\Games\\COD4\\";
String cmd = workingDir + "iw3mp.exe";
Runtime.getRuntime().exec(cmd,null,new File(workingDir));

iw3mp.exe probably isn't on your system path so you have to give Java an absolute path to the executable.

Dave Ray
A: 

Thank you! It worked! Finally!! :D