learn java
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 The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "problem with waiting for a process" Watch "problem with waiting for a process" New topic

problem with waiting for a process

Ram Sateesh Talari

Joined: Dec 03, 2003
Posts: 20

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:
new Thread()
public void run()
Process p = Runtime.getRuntime().exec("perl c:/basepairfinder/final.pl "+path);
int i = p.exitValue();
catch (Exception e)
throw new RuntimeException(e.getMessage());

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

catch (Exception e2)

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

Joined: Jul 08, 2003
Posts: 24189

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]
Have you tried LearnNowOnline? http://www.learnnowonline.com/
subject: problem with waiting for a process