aspose file tools*
The moose likes Java in General and the fly likes How to run a batch file from a program? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to run a batch file from a program?" Watch "How to run a batch file from a program?" New topic
Author

How to run a batch file from a program?

Ravi Sathish
Ranch Hand

Joined: Feb 26, 2002
Posts: 131
Hi Ranchers
I hope this is the right forum for my question.
Let me state the problem I have at hand....
I have a batch file abc.bat with following lines:
cd c:\GoToDestination
java -cp runNewProgram
How to execute a batch file from my program?
TIA
Ravi
Aneesha Singh
Ranch Hand

Joined: Jan 14, 2002
Posts: 47
You can use the Runtime class to execute the batch file. Use getRuntime() to access the current runtime environment as you cant create your own instance of the runtime class. The following is the code:

This returns a Process object.
Jean-Francois Briere
Ranch Hand

Joined: Mar 03, 2004
Posts: 101
You should do, on Windows NT4/2000/XP/2003:

Then on Windows 95/98/98SE/ME:

If the batch file does output at the console, then you must grab it.
Here is a more thorough explanation from JavaWorld.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to run a batch file from a program?