aspose file tools*
The moose likes Java in General and the fly likes executing batch file from a java program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "executing batch file from a java program" Watch "executing batch file from a java program" New topic
Author

executing batch file from a java program

Neeraj Gupta
Greenhorn

Joined: Jun 21, 2003
Posts: 10
Hi,

Can anyone please help me with code that how to execute a Windows based batch file through a simple java program.

I tried Runtime.exec() but its not working.

Assume that the batch file is kept at C:\ABC.bat

Neeraj
Lionel Badiou
Ranch Hand

Joined: Jan 06, 2005
Posts: 140
What about this ?


Hope that helps,


Lionel Badiou
CodeFutures Software
Lionel Badiou
Ranch Hand

Joined: Jan 06, 2005
Posts: 140
Horatio Westock
Ranch Hand

Joined: Feb 23, 2005
Posts: 221
I think for a batch file, you have to pass it as a parameter to cmd.exe or command.com depending on your version of windows:

e.g. rt.exec("cmd.exe /C C:/test.bat");

Or use an array for the parameter with the arguments, your choice.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12682
    
    5
And remember that you have to provide for handling the output stream (std out) from the batch or it may never complete. This has been discussed here frequently, so browse the archives.
Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: executing batch file from a java program
 
Similar Threads
Thread Related Problem
help regarding batch file
java program that can run a .class file in msdos, is this possible?
calling batch files
Running code