• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problem with waiting for a process

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Oh the stink of it! Smell my tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic