• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with waiting for a process

 
Ram Sateesh Talari
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic