Indirect Spawn Ids
Indirect spawn ids are lists of direct spawn ids that are stored in global variables; the variables are in turn passed by name. Whenever the variables are modified, commands using them as indirect spawn ids recognize this. (This is described in more detail in Chapter 11 (p. 264).) Indirect spawn ids may be used in the interact command, similarly to the way they are used in the expect command. However, they are much more useful in the interact command, simply because interact commands are usually long-lived.
Indirect spawn ids may appear anywhere that explicit spawn id lists can. In the expect command, spawn id lists appear only as arguments to −i flags. In the interact command, spawn id lists appear as arguments to −i, -u, -input, and -output flags.
The following script connects to two hosts and allows you to interact with either one. Pressing ^A causes further interaction to occur with hostA. Pressing ^B causes further interaction to occur with hostB.
spawn telnet hostA; set A $spawn_id
spawn telnet hostB; set B $spawn_id
set proc $A
interact {
"\1" {set proc $A}
"\2" {set proc $B}
-i proc
}The variable proc is used to contain the indirect spawn id, but any variable can be used, even spawn_id. While spawn_id is the default, interact is not sensitive to changes in spawn_id unless it is explicitly named as an indirect spawn id.
Here is a different way to control the same scenario. In this case, ^A is used to toggle between the two processes.
spawn telnet hostA set old ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access