This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes problem with waiting for a process Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "problem with waiting for a process" Watch "problem with waiting for a process" New topic
Author

problem with waiting for a process

Ram Sateesh Talari
Greenhorn

Joined: Dec 03, 2003
Posts: 20
Hi,

My problem is as follows i am calling a perl script from a java program using runtime.getruntime.exec and the problem is that i am not able to make the java program wait until whole of the perl script execution is completed.
the code is as follows:
try
{
new Thread()
{
public void run()
{
try
{
Process p = Runtime.getRuntime().exec("perl c:/basepairfinder/final.pl "+path);
p.waitFor();
int i = p.exitValue();
}
catch (Exception e)
{
throw new RuntimeException(e.getMessage());
}
}
}.start();

JOptionPane.showMessageDialog(this, "Process Completed :"+path);

}
catch (Exception e2)
{
System.out.println(e2);
}


kindly help me out in this
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

You're starting the process from a separate Thread, and that thread is correctly waiting for the process, but of course the parent thread doesn't wait for the child thread. You have two choices: first, you could simply do away with the child thread. If you're going to wait for the process, this is probably the cleanest solution. The other alternative, though, is to wait for the thread. You'd have to store your anonymous thread in a variable, then call start() on that variable, and then call join() on that variuable, which won't return until the Thread terminates.


[Jess in Action][AskingGoodQuestions]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: problem with waiting for a process
 
Similar Threads
calling a perl script from java program
Error 35 Resource Temporarily Unavailable
Web interface to delete folder
Process p .waitFor() waits for ever please give suggestions
Shell script from a java application