Runtime.exec() slight weirdness

Posted by Simes at 5:13 pm
Oct 042007

Change working directory of java code to location of batch file before code is launched, call rt.exec("batchfile.bat"), batch file runs.
Leave working directory alone, call

File dir = new File("C:\\path\\to\\batch\\file");
rt.exec("batchfile.bat", null, dir);

Batch file does not run, giving a file not found error.

Change second line to rt.exec("cmd /c batchfile.bat", null, dir); – batch file runs.

I’m not sure why this is, but I thought the information might be useful to someone.

Sorry, the comment form is closed at this time.

© 2011 simes dot org Suffusion theme by Sayontan Sinha