开发者

how to get java to run an application and when user closes the application, java runs another process in mac or windows

开发者 https://www.devze.com 2023-03-08 20:24 出处:网络
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 the

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:

  1. Use ProcessBuilder or Runtime.exec to get hold of a Process.
  2. Start the process by doing process.start().
  3. 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();
0

精彩评论

暂无评论...
验证码 换一张
取 消