Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
    
To stop a program send SIGSTOP, usually mapped to Ctl-Z. If run under expect you should be able to use kill command with SIGSTOP, but I don't remember the details. –  Keith Apr 20 '11 at 11:22
add comment

2 Answers

See if this works: package require Tclx

If it can, then you can trap signals with the signal command.

share|improve this answer
    
expect is supposed to have its own facility 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 executed, 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
    
@LaC, why don't you spawn it instead of exec'ing it? –  glenn jackman Apr 20 '11 at 13:23
    
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
add comment
up vote 0 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.