Default Input And Output

When the interact command is given with no arguments, it is equivalent to:

interact {
    -input $user_spawn_id -output $spawn_id
    -input $spawn_id -output $user_spawn_id
}

Besides omitting all of the arguments, it is possible to omit just some of them and still get reasonable defaults. There are defaults for the first two processes since an interaction invariably involves at least two processes.

If the first -input is omitted, user_spawn_id is used. If the first -output is omitted, spawn_id is used. If the -output after the second -input is omitted, user_spawn_id is used. These can also be affected by the -u and −i flags. For example, if the -u flag appears, the new spawn id is used in place of the first -input.

As an example, the following command establishes a connection between the user and an external process (not started by Expect). The external process provides two fifos for communication, one for input and one for output.

interact -output $out -input $in

The first input is implicit and is therefore user_spawn_id. User keystrokes are sent to out. Input from in is sent back to user_spawn_id so that the user can read it. The following figure shows the Expect process with the interact in progress.

Figure 16-2. 

The external process could be a C program, but it is also expressible as another Expect script with an interact of its own. For example, the second script ...

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.