Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-01-2004, 07:46 PM   PM User | #1
JPM
Regular Coder

 
Join Date: Mar 2004
Location: Norway
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
JPM is an unknown quantity at this point
Java. Starting Batch files

Is it possible to start a batch file from java program?
__________________
<JPM />
JPM is offline   Reply With Quote
Old 12-01-2004, 09:30 PM   PM User | #2
turbowrx
New Coder

 
Join Date: Nov 2004
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
turbowrx is an unknown quantity at this point
Yes it is.

PHP Code:
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.
turbowrx is offline   Reply With Quote
Old 12-02-2004, 05:49 PM   PM User | #3
JPM
Regular Coder

 
Join Date: Mar 2004
Location: Norway
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
JPM is an unknown quantity at this point
Thanks, it works great! Just on thing; what is the '/c' good for?
__________________
<JPM />
JPM is offline   Reply With Quote
Old 12-03-2004, 12:29 AM   PM User | #4
turbowrx
New Coder

 
Join Date: Nov 2004
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
turbowrx is an unknown quantity at this point
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.
turbowrx is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:29 PM.


Advertisement
Log in to turn off these ads.