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


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "java.land.Runtime" Watch "java.land.Runtime" New topic
Author

java.land.Runtime

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.

basically..


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
Bartender

Joined: Oct 29, 2001
Posts: 8996
    
    9

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.


[How To Ask Questions On JavaRanch]
Rich Stepanski
Ranch Hand

Joined: Aug 24, 2004
Posts: 59
http://mindprod.com/jgloss/exec.html

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.

Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.land.Runtime