File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other JSE/JEE APIs and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "" Watch "" New topic

Rich Stepanski
Ranch Hand

Joined: Aug 24, 2004
Posts: 59
I've found a couple different examples on how to execute a bat file from java.


I've tried command = a filepath , dos command, and only a file name (no directory)- all of which don't seem to work. The complete filepath doesn't throw an error but it also doesnt execute the bat, while the other two both throw an IO error. I'm using NetBeans 3.6 on XP - any idea what the problem is?
Rich Stepanski
Ranch Hand

Joined: Aug 24, 2004
Posts: 59
java.lang.Runtime... not land.... too late now
Joe Ess

Joined: Oct 29, 2001
Posts: 8876

Batch files and DOS commands are not executable. They cannot be run on their own. They must be executed by the command shell, cmd.exe. try:

Keep in mind that the Process returned by exec() has a finite buffer for I/O, so you should really be reading from its input and error streams, otherwise your process may halt without warning. Not to mention the output could be useful for debugging.

"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Rich Stepanski
Ranch Hand

Joined: Aug 24, 2004
Posts: 59

I found some help here - I dont really understand what the /E:1900 is but I guess I'm runnin the bat through the cmd.exe like you suggested. This begins to open the program but wont fully open it until I close my java app? I'm still not reading any of the output from the program - could this be the cause?

Note: Program runs after I close my app - doesn't crash. Also, the bat I am running opens another Java application.

I agree. Here's the link: