3

From within a MATLAB GUI application, I'm starting an external program (a console application on Windows) that takes care of reading data from a measurement system. The data is stored in several files that are processed by the MATLAB application as soon as the external program has finished. The problem is this:

The external program, when run on the command line, can be gracefully stopped by issuing a SIGINT (i.e. by pressing Ctrl + C). A signal handler traps the SIGINT and shuts down the program. Is there a way to do this from within the MATLAB GUI application, by pushing an "abort" button?

After many hours of searching I stumbled upon http://www.caam.rice.edu/~wy1/links/mex_ctrl_c_trick/ which shows how to detect SIGINT in a MEX file. Letting a MEX call the external program might work (although I'm not sure about the details yet). However, it still requires Ctrl + C to stop the program. How can I send the SIGINT via push button in my GUI?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Atze Kaputtnik
  • 262
  • 3
  • 10
  • 1
    Have you seen http://stackoverflow.com/questions/813086/can-i-send-a-ctrl-c-sigint-to-an-application-on-windows ? You did say that you are under Windows, right? – Jonas Heidelberg Jul 13 '11 at 23:26
  • possible duplicate of [Matlab: implementing what CTRL+C does, but in the code](http://stackoverflow.com/questions/10033078/matlab-implementing-what-ctrlc-does-but-in-the-code) – Jonas Apr 18 '12 at 19:12

1 Answers1

0

If you start your external program in Cygwin, then Cygwin will give it a PID. Using this PID you can use Cygwin's kill command to send signals to the process. So start the program from Cygwin. In MATLAB you can use !ps (where ! means call external shell command) to get a list of Cygwin PID's and then !kill -s signal pid to send a signal to the program. To make it happen from a MATLAB GUI let the callback from some button call !kill.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
snowape
  • 1,274
  • 10
  • 23