aspose 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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 19538
    
  16

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: 36453
    
  15
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Executing a .bat file using Java
 
Similar Threads
Runtime
How to get a value from process
How to capture events from vbs script in java
How to chech process is successful
Wrapper application cannot execute scripts properly