3

I'm running MATLAB (command line version) from a shell script, and I'd like it to preserve shell behavior where if you press Ctrl-C it exits. But instead it wants to keep control of the terminal and I (or my poor users after me) have to type quit(1) to make it quit and tell the shell it failed.

You can't intercept Ctrl-C with a try/catch block... any other ideas? Anything I could do from the shell side to intercept the keystrokes before they get to MATLAB?

onCleanup seems like an option, but then I'd have to make the whole script thing into a function (it's already a dynamically generated try/catch block thing in a Makefile). But if that's the only thing that will work, then I'll do it...

MatlabDoug
  • 5,704
  • 1
  • 24
  • 36
rescdsk
  • 8,739
  • 4
  • 36
  • 32

2 Answers2

1

Use onCleanup:

I wanted to do the same thing but after I read this thread I used onCleanup successfully. My problem was I had a server in Matlab that when pressing CTRL+C would keep listening on the port it was started on -> second run I would get a bind error.

INS
  • 10,594
  • 7
  • 58
  • 89
0

You can try:

stty quit ^C

but I have no matlab to test it.

Michał Šrajer
  • 30,364
  • 7
  • 62
  • 85