Java Execute external exe

时间:2015-05-12 23:45:38

标签: java

I have this:

for (i = 0; i < 1000000; i++) {
    [... a bunch of calculations ...]
    if (i % 10000 === 0) {
        SELF.postMessage({msg:'progress', percent:i/1000000});
    }
}
SELF.postMessage({msg:'complete'});

And I get the following error:

java.io.IOException: Cannot run program "toolUpdate.exe" (in directory "C:\Users\blah\AppData\Roaming"): CreateProcess error=2, The system cannot find the file specified

If I look at the directory I can see the file that I want to execute, I just can't get it to execute using that piece of code above.

This worked for me :

Runtime.getRuntime().exec("toolUpdate.exe", null, new File(location));

1 个答案:

答案 0 :(得分:0)

我认为您可以通过以下代码更改来解决方法1。

Runtime.getRuntime().exec(location + "toolUpdate.exe");