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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Execute a batch file from java" Watch "Execute a batch file from java" New topic
Author

Execute a batch file from java

Blikkies Marais
Ranch Hand

Joined: Jun 12, 2003
Posts: 50
Hi
I am trying to execute a batch file from within a java application. I do the following:
Runtime rt = Runtime.getRuntime();
rt.exec("cmd /c X:\\Java\\WSAD\\workspace\\xrad2\\webApplication\\xrad\\config\\startup.bat");
But the batch file is not executed. A dos prompt is propted, but the batch file is not executed. Any suggestions please?
Blikkies Marais
Ranch Hand

Joined: Jun 12, 2003
Posts: 50
Sorry, this does work. Only the echo in the batch file is not displayed.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Right. Java collects the output from a process and makes it available through the Process object returned by exec(). You can call getInputStream() on the Process to get a stream from which you can read the output. If you want it to go to the screen you can just System.out.print() everything you read.


[Jess in Action][AskingGoodQuestions]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Try "CMD /K start X:\\Java\\WSAD\\workspace\\xrad2\\webApplication\\xrad\\config\\startup.bat"
[ October 28, 2003: Message edited by: Dirk Schreckmann ]

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Execute a batch file from java
 
Similar Threads
Can i host web service through batch file
calling batch files
How to execute java class held in jar file from dos batch file?
executing class files held in different jar files from Dos
help regarding batch file