File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 24184
    
  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]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem with waiting for a process