...

View Full Version : Java. Starting Batch files



JPM
12-01-2004, 07:46 PM
Is it possible to start a batch file from java program?

turbowrx
12-01-2004, 09:30 PM
Yes it is.



try {
Runtime.getRuntime().exec(
"cmd.exe /c start j:\\somefile.bat");
}
catch (Exception e) {
e.printStackTrace();
}



This should work for simple batch files, but there may be some classpath issues if your batch file starts looking for other files.

Also, instead of the string I have there, you can also place the path to an exe and it will run, or any file for that matter. Windows will open it with whatever the default program is.

This is just one method of doing it. There are others that are very similar. Later. Hope it works.

JPM
12-02-2004, 05:49 PM
Thanks, it works great! Just on thing; what is the '/c' good for?

turbowrx
12-03-2004, 12:29 AM
To be totally honest, I'm not sure.

cmd.exe is the command prompt. I believe the /c has something to do with opening the command window, although I could be incorrect. The start command runs the next token in the string. If you were to put a text file after it instead of a batch file, it should use your default editor to open the file. Hope this helped.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum