views:

455

answers:

3

I've got a command line version of an Eclipse RCP GUI application that can makes use of a lot of the same plugins (this is handy for integration testing). One thing it does is connects to a server, requests stuff and starts an interactive loop. To exit, the user of the GUI app can stop the loop and close the application.

In my command line app, the most obvious way to "close" the application is CTRL-C! However this leaves "session crud" on the server that can be cleaned up if I can capture the exit signal. The crud will eventually time out or whatever, but it'd be nice if I could sort it out cleanly too.

So, what are my options for capturing a kill signal from an Eclipse RCP application? This is Linux specific, if that helps. But I don't load any SWT plugins. My "main loop" Plugin.stop() is not called when I ctrl-c the command line. Something like Python's KeyboardInterrupt would be ace!

+1  A: 

Look at bash's trap builtin. The signal for CTRL-C is SIGINT, but you may want to also trap SIGTERM and SIGHUP.

cadrian
+2  A: 

I found an alternative approach - add a shutdown hook that is run when the end arrives...

 Runtime.getRuntime().addShutdownHook(new Thread() {
  public void run() {
   System.out.println("The end.");
  }
 });
rq
A: 

Can you share any tips for making a command line version for an Eclipse RCP? I have a RCP consisting non-UI plugins and UI plugins. Thanks!