Expect Commands
The library provides functions that can be used to read files or streams. Like the Expect program’s expect command, the library functions wait for patterns to appear or special events to occur.
There are four functions to do expect-like processing. Two are for handling file descriptors, and the other two are for streams. One of each take lists of arguments similar to exp_spawnl while the others take a single variable argument descriptor similar to exp_spawnv. I will occasionally refer to these functions generically as the “expect functions”.

Figure 21-1. Table of expect functions—each function is prefixed with "exp_
The names are mnemonic. Like exp_spawnl and exp_spawnv, the expect functions that end with an "l" take arguments lists, and those ending with "v" take a single variable descriptor. An "f" means that the function reads a stream; otherwise it reads from a file descriptor.
The table shows the short names but these are further prefaced by the string "exp_“.[70] For example, the exp_expectl function takes an argument list and reads from a file descriptor. A simple example of exp_expectl is:
exp_expectl(fd, exp_glob, "prompt*", 1, exp_end);
This call waits for a prompt to arrive from the file descriptor fd. exp_glob is the pattern type. It says that the pattern "prompt*" is a glob pattern. When it arrives, exp_expectl returns the value 1.
More patterns can be expected ...