View Full Version : Java. Starting Batch files

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

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

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

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.

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

12-03-2004, 01: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.