aspose file tools*
The moose likes Beginning Java and the fly likes waitFor method of a process object not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "waitFor method of a process object not working" Watch "waitFor method of a process object not working" New topic
Author

waitFor method of a process object not working

vinayak jog
Ranch Hand

Joined: Apr 01, 2011
Posts: 76

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

Joined: Jan 21, 2011
Posts: 129

I also had the same problem, long time ago and was unable to solve. Any help is greatly appreciated.
vinayak jog
Ranch Hand

Joined: Apr 01, 2011
Posts: 76

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

Joined: Aug 25, 2003
Posts: 227

Your questions will be answered in this article. I highly recommend going through it before using Runtime.exec().
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: waitFor method of a process object not working
 
Similar Threads
execute external program
Multiple instances of java class
problem with waiting for a process
Runtime.getRuntime().exec("sh export LC_ALL=C") fails!!!!!!!!!!
the exec command is not able to deal with space some time