You have to read the output before the process will terminate. You're assuming all the output from the process will be saved somewhere for you to read later, but that's not how it works; if you want to save the output, then you need to do that yourself by reading it all and then storing it someplace.
You can't ask for the exit status until the process has exited; you have to call waitFor to wait for that to happen.
I am facing a similar problem.I am trying to execute some external process with Process.getRuntime.exec. I am also using a java Time with this. The main idea is to see if the process does not execute within certain seconds, the java time api calles the process.destroy. But I see that, when I call destroy, the process does waits for some time, after calling it.
Am I doing right, or is there any other way to destroy the process after a specified time.
To the original post ... if your process writes to errout, you will need to read that stream to completion, too. Because it might alternate lines to stdout and errout, you pretty much have to read them both on independent threads. With everything on separate threads, I found that waitFor() returned before the streams ran out. There must be some buffering in there somewhere, but not enough to avoid your original problem.
To Shashank, I'm not sure what happens in destroy(). It could be the other process is in the middle of something that's not interruptable, or should we expect the OS to be able to kill the process no matter what it's doing?
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
We're all out of roofs. But we still have tiny ads:
Programmatically Create PDF Using Free Spire.PDF with Java