Daily Archives Thursday, October 2007

Runtime.exec() slight weirdness

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 [...]