Chapter 16. Interacting With Multiple Processes

The previous chapter had numerous examples, all showing how to create a connection between a user and the currently spawned process. The interact command does this by default, but it is possible to create connections in other ways. In this chapter, I will cover how to use the interact command with a process other than the user and currently spawned process, or with multiple processes.

Connecting To A Process Other Than The Currently Spawned Process

Like many of the other commands in Expect, the interact command accepts the −i flag to indicate a spawn id to be used in place of the currently spawned process. For example:

spawn telnet
set telnet $spawn_id
spawn ftp
interact −i $telnet

In this example, interact connects the user to the telnet process. Without the "-i $telnet“, the ftp process is connected.

Output from the process is tested against any patterns appearing after the −i flag. In other words, the −i behaves as if a -o flag had also appeared.

Connecting To A Process Instead Of The User

Just as the −i flag allows substitution of one side of the connection created by interact, the -u flag allows substitution of the other side. Specifically, the -u flag identifies a process to be used instead of the user.

spawn proc1
set proc1 $spawn_id
spawn proc2
interact -u $proc1

The interact command above connects the input of proc1 to the output of proc2 and vice versa. The processes interact as shown in the following figure.

Figure 16-1. With the ...

Get Exploring Expect now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.