Expect - Interrupt program - Ctrl+C Expect - Interrupt program - Ctrl+C linux linux

Expect - Interrupt program - Ctrl+C


To send a Ctrl+C, do:

send \x03

To handle an incoming Ctrl+C, do:

trap {your handler script here} SIGINT

You might want to make the handler script (which can be a multi-line thing) send the signal on to the inner process…

trap {    send \x03    send_user "You pressed Ctrl+C\n"} SIGINT

But take care! When the user presses Ctrl+C in a text-mode program (in most GUIs, it's a copy action) they are usually expecting it to go away pretty soon, so you should take care to ensure that you don't spend too long after the signal arrives cleaning everything up.