• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

waitFor method of a process object not working

 
vinayak jog
Ranch Hand
Posts: 83
MySQL Database Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the error in this program

In this program i am trying to execute a batch file using java.
output "wait completed" is printed even before the process p completed ! why is that so? it is working well with eclipse not working in netbeans i m using netbeans 6.9 with jdk 1.6
 
Nitin Surana
Ranch Hand
Posts: 129
Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also had the same problem, long time ago and was unable to solve. Any help is greatly appreciated.
 
vinayak jog
Ranch Hand
Posts: 83
MySQL Database Netbeans IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nitin Surana wrote:I also had the same problem, long time ago and was unable to solve. Any help is greatly appreciated.

I have done a small work around and its working as of now its not a legal solution

and remove p.waitFor
add small code at the end of the batch file


when work is over batch file executes the exit statement and it will return controll to the program then p.getInputStream().read() will return -1 this will indicate end of execution untill -1 is got the main thread will wait for process. "This worked for me" might work for you also
 
Aditya Jha
Ranch Hand
Posts: 227
Eclipse IDE Java Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your questions will be answered in this article. I highly recommend going through it before using Runtime.exec().
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic