Hi all i m trying to write a java program to open an application on a mac, wait in the background until the user closes the application, th开发者_C百科en the java program performs another task. is there a way to know when the user has closed the application started by java?
thanks
is there a way to know when the user has closed the application started by java?
Sure, here's how:
- Use
ProcessBuilder
orRuntime.exec
to get hold of aProcess
. - Start the process by doing
process.start()
. - Then call
proccess.waitFor()
to block until the external program terminates.
This should work fine on Mac and Windows systems.
Example:
ProcessBuilder pb = new ProcessBuilder("/usr/bin/emacs");
Process proc = pb.start(); // start external program
proc.waitFor(); // wait for it to terminate
performAnotherTask();
精彩评论