• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Executing a .bat file using Java

 
Santosh Ghule
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,,, it helped... working fine..
 
Rob Spoor
Sheriff
Pie
Posts: 20494
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When Runtime.exec() won't. Read it, seriously.

Oh, and UseCodeTags next time.
 
Campbell Ritchie
Sheriff
Posts: 48382
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic