I am running windows 7 and have an exe file I am trying to run using the following command in Java:
File dir = new File("C:\\PATH\\TO\\DIR");
String[] cmdArray = {"file.exe"};
if(dir.exists()){
for(String s : dir.list()){
if(s.equals(cmdArray[0]))
System.out.println("File exists!");
}
}
Runtime.getRuntime().exec(cmdArray,null,dir);
The exec(...) command, however, gives me this error:
Cannot run program "file.exe" (in directory "C:\PATH\TO\DIR"): CreateProcess error=2, The system cannot find the file specified
The above code does print out "File Exists!" so the file is there and Java knows it is there. I dont know how this is possible.
Also, I need to use Runtime.getRuntime().exex(...). This call is actually inside another method that I am not suppose to change so alternative solutions will not work for me. Thanks in advance!
EDIT: I ran the file in a cmd window without admin privileges and got the following message:
Error in Opening Configuration File in Read Mode
So I assume I have permission issues. How would I change the permissions in order for me to be able to run it?
EDIT2:
I tried changing cmdArray to this:
String[] cmdArray = {"C:\\PATH\\TO\\DIR\\file.exe"};
and it worked like a charm. One question though. Why did this work but not the other way? I assumed that Runtime.exec() ran at a high level like so in a cmd wibndow:
pushd dir
cmdArray[0] cmdArray[1] cmdArray[2] ... cmdArray[length - 1]
popd dir
Is this the wrong assumption?