Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know when a process has exited?

Tags:

java

process

exit

For a Java Process, I see a method to get the exit code, but how do I know when the process exited?

I'd like to fire an event when my Process is finished running...

like image 402
Tony R Avatar asked Dec 02 '25 21:12

Tony R


1 Answers

Process.waitFor()

If you want to fire an event without stopping your current thread, start a thread that launches the process, calls waitFor(), and then fires the event when the time is right.

Thread.start(new Runnable() {
  public void main() {
    Process p = startProcess()
    p.waitFor()
    fireEvent()
  }
})
like image 112
Reverend Gonzo Avatar answered Dec 04 '25 11:12

Reverend Gonzo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!