• Post Reply Bookmark Topic Watch Topic
  • New Topic

Process.waitFor is left hanging even after sub child process terminates  RSS feed

 
Paul Agola
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am attempting to use Runtime.exec to launch a process from a Java program. The requirements state that i must suspend the parent process and wait until the child process has been closed and then return continue with the parent process. The parent process is a GUI and i launch the child process from a menu item. I have a specific utility class that is responsible for launching the process. Below is a sample of the code and where i think the problem is.



The problem is that is just keeps hanging and even when i terminate the sub child process it still hangs and the GUI is frozen. I know many people will recommend the java article about when runtime exec won't execute but as you can see from the code above i have created a StreamGobbler class which handles both the input and output streams of the child process so i do not understand why it keeps hanging?
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1103
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The while loop doesn't make any sense to me. You run a process and it completes and provides an exit value - an exit value of 0 indicates success and other values indicate some issue.
So, suppose your process ran and provided an exit value other than 0, you are simply looping around doing nothing. The repeated call to waitFor() does nothing if the process has already completed.

You just need to call the waitFor and based on the exit value identify the result of the process and proceed accordingly.

I think you should go through the Process API documentation.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!