java - how to open a program and detect when the program is closed
<p>My main method opens an app and sets <code>running</code> to false after it has finished executing, the only problem is that I want to to set <code>running</code> to false only once the opened app has been closed. Is there any easy way to do this?</p>

<p>This is my code:</p>

<pre><code>Runtime runtime = Runtime.getRuntime();
boolean running = true;
try {
    Process p = runtime.exec("open test.app");
    p.waitFor();
} catch (InterruptedException e) {}
running = false;
</code></pre>

<p>EDIT: What happens at the moment is it opens <code>test.app</code>, then it sets <code>running</code> to false even though the app is still running.</p>
