My main method opens an app and sets running to false after it has finished executing, the only problem is that I want to to set running to false only once the opened app has been closed. Is there any easy way to do this?
This is my code:
Runtime runtime = Runtime.getRuntime();
boolean running = true;
try {
Process p = runtime.exec("open test.app");
p.waitFor();
} catch (InterruptedException e) {}
running = false;
EDIT: What happens at the moment is it opens test.app, then it sets running to false even though the app is still running.
Seems that
openstarts app and exits. So you still see something running, and java sees that process finished. I guessing you are doing it on MacOS. I’ve never touch Macs myself, but documentation foropencommand states that you need pass-Woption to forceopenwait for app termination:Process p = runtime.exec("open -W test.app");