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.