Using A Different Interpreter To Process Signals

This section is only useful if you have multiple interpreters in a single process. If you are using vanilla Expect, then you can skip this section.

By default, the signal handler is evaluated in the interpreter in which the trap command was evaluated. It is possible to evaluate the handler in the interpreter active at the time the signal occurred by using the -interp flag.

For example, if you are running several simulations whose speeds are controlled by the variables speed (one per interpreter), you could reverse the speed by pressing ^C with the following definition in effect:

trap -interp {
    set speed [expr -speed]
} SIGINT

Get Exploring Expect now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.