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

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”.

Table of expect functions—each function is prefixed with "exp_

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 ...

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