wood burning stoves 2.0*
The moose likes Java in General and the fly likes How to run dos batch file from java program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to run dos batch file from java program" Watch "How to run dos batch file from java program" New topic
Author

How to run dos batch file from java program

James Ajewole
Greenhorn

Joined: Apr 02, 2003
Posts: 19
Hi,
How can i run a dos batch command from a java program. For example i want to run a dos batch file after executing a java program, and i want to initiate the dos batch command from the java program. thanks
james
John Ipe
Greenhorn

Joined: Dec 29, 2003
Posts: 25

what did you mean by "initiate the dos batch command"?
regards
John Ipe
Greenhorn

Joined: Dec 29, 2003
Posts: 25
if you mean you want to pass parameters to the batch file from the java pgm, you could append those as Strings after the batch file name:

and your batch file would read param1 and param2 with %1 and %2 respectively. is this what you needed?
regards
James Ajewole
Greenhorn

Joined: Apr 02, 2003
Posts: 19
thanks john, i'll try out the command.
James Ajewole
Greenhorn

Joined: Apr 02, 2003
Posts: 19
hi john,
unfortunately it didnt work. I tried to execute a simple bat file to echo something but i never saw anything echoed on the screen.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

It won't go to the screen. It will go to the process's standard output, which is available from the Process object created by Runtime.exec(). You call getInputStream() on the Process, and, if you want, you read data out of the InputStream and display it on the console; something like


[Jess in Action][AskingGoodQuestions]
 
wood burning stoves
 
subject: How to run dos batch file from java program