Tony R
Tony R

Reputation: 11524

How to know when a process has exited?

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...

Upvotes: 3

Views: 2308

Answers (1)

Reverend Gonzo
Reverend Gonzo

Reputation: 40811

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()
  }
})

Upvotes: 8

Related Questions