Skip to Content
Exploring Expect
book

Exploring Expect

by Don Libes
December 1994
Intermediate to advanced
606 pages
16h 7m
English
O'Reilly Media, Inc.
Content preview from Exploring Expect

Sending To Multiple Processes

Unlike the expect command, the send command has no built-in support for sending to multiple processes simultaneously. The support is not necessary, since it is possible to achieve the same effect by writing a group of send commands or by writing one in a loop or procedure. For example, a string can be sent to a list of processes with the following command:

foreach spawn_id $procs {
    send $string

}

Notice that spawn_id is implicitly set by the foreach command. This is analogous to a formal parameter except that spawn_id retains the last value after the foreach finishes. This could be avoided by using a different variable and then passing it explicitly with −i, or alternatively by placing the entire command in a procedure.

In comparison, waiting for output from multiple processes cannot be simulated easily, hence it is built in. A number of other options are built into the send command because they are inherently difficult to achieve. These will be covered in the remainder of this chapter.

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.
Start your free trial

You might also like

AI Agents in Action

AI Agents in Action

Micheal Lanham
Learning Go

Learning Go

Jon Bodner

Publisher Resources

ISBN: 9781565920903Supplemental ContentErrata Page