File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Executing a .bat file using Java 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 » Java in General
Bookmark "Executing a .bat file using Java" Watch "Executing a .bat file using Java" New topic
Author

Executing a .bat file using Java

Santosh Ghule
Greenhorn

Joined: Aug 20, 2010
Posts: 7
Hi,

I am trying to execute a batch file from java.
But for some reason my batch file is not completely executing ..
when get the exitValue, i get an exception..

here is the code..


Code of Test.bat


and exception..



Error creating the FileInfo panel: java.lang.IllegalThreadStateException: process has not exited
java.lang.IllegalThreadStateException: process has not exited
at java.lang.ProcessImpl.exitValue(Native Method)
at com.component.Batch.main(Batch.java:10)
Sridhar Santhanakrishnan
Ranch Hand

Joined: Mar 20, 2007
Posts: 317
The batch job has not finished running by the time you check the job status. Instead of exit(), why dont you try using waitFor() ?
Santosh Ghule
Greenhorn

Joined: Aug 20, 2010
Posts: 7
Thanks,,, it helped... working fine..
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19672
    
  18

When Runtime.exec() won't. Read it, seriously.

Oh, and UseCodeTags next time.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38412
    
  23
Rob Prime wrote:When Runtime.exec() won't. Read it, seriously.
Agree. It's essential reading. It is a bit easier now that ProcessBuilder has been created, but you still need what Daconta told youi
Oh, and UseCodeTags next time.
Since he's new and hasn't posted code before, I've edited the post and we can all see how much better it looks.
 
Don't get me started about those stupid light bulbs.
 
subject: Executing a .bat file using Java