This week's giveaways are in the MongoDB and Jobs Discussion forums.
We're giving away four copies of Mongo DB Applied Patterns and 4 resume reviews from Five Year Itch and have the authors/reps on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes Running Batch Files Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Running Batch Files" Watch "Running Batch Files" New topic
Author

Running Batch Files

Amit Lonkar
Greenhorn

Joined: Dec 12, 2001
Posts: 25
Hi All!!!
Can anyone tell me how to run ".bat" files from Java. Currently I am using Runtime.exec("c:\\TestBat.bat");
But this does not work.
Amit
Arun Boraiah
Ranch Hand

Joined: Nov 28, 2001
Posts: 233
Can you tell what was the error displayed.
try this
1. Check the presence of file name
2. File name case
-arun


Sharing is learning
Matt Siegel
Ranch Hand

Joined: Jul 18, 2000
Posts: 55
Hi Amit,
You are going to want to use the Runtime.exec(String[] cmdarray) method. Here's some code:

But remember you won't see any output from the batch file on the command line when it is run. You will need to grab the streams from the Process object.
HTH,
Matt
Amit Lonkar
Greenhorn

Joined: Dec 12, 2001
Posts: 25
Hi
I tried Running the batch file as :=
String[] cmds = {"cmd", "/c", "c:\\TestBat.bat"};
Process proc = Runtime.getRuntime().exec(cmds);
The program runs. But does not show the command prompt.
Thanks
Amit
Amit Lonkar
Greenhorn

Joined: Dec 12, 2001
Posts: 25
Sorry I did not see the last line. Trying it out...
Thanks
Amit
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Running Batch Files
 
Similar Threads
How to create a war file.
WA #1.....word association
Componentized logic in views - what to use.
ClassNotFoundException in Jsp Precompilation
Need to Convert Documents to HTML