While exec is running a program, I would like Ctrl-C to terminate the program and resume the script, instead of killing the script. What's the best way of accomplishing that?
Asked
Active
Viewed 1,728 times
2 Answers
0
See if this works: package require Tclx
If it can, then you can trap signals with the signal command.
glenn jackman
- 25,463
- 6
- 46
- 69
-
expect is supposed to have [its own facility](http://rosettacode.org/wiki/Handle_a_signal#Tcl) for catching signals. The problem is that, assuming that the initial SIGINT is sent to `expect` and my script catches it, I'd need to send a SIGINT to the program being `exec`uted, but I don't know how to get its PID. `exec` only returns a PID if you background the process, for obvious reasons. – LaC Apr 20 '11 at 13:21
-
-
I used `exec` because I just want to run the program until it completes. I tried using `spawn` followed by `wait`, but that makes it completely impervious to SIGINT. I ended up having to suspend and kill -9. I tried installing a signal handler for SIGINT but it does not get called. – LaC Apr 20 '11 at 13:37
0
I ended up running the program using exec and using expect's trap command to intercept SIGINT. The subprogram is still terminated (in fact, there may not be a way to avoid this is using exec), but by using trap and a catch around exec, the tcl script can continue executing.
LaC
- 2,819
- 2
- 20
- 19