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

The - Flag

Normally, Expect reads commands from a script. And if no script is named on the command line (or the −i flag is used), Expect prompts to the standard output and reads commands from the standard input.

The "-" flag tells Expect to read commands from the standard input without prompting. Using "-“, another program that is dynamically generating commands can redirect them to the standard input of Expect.

Strictly speaking, the "-" is not a flag but a reserved file name. (Using a "-" for this is a common UNIX convention.) Therefore, the "-" must appear separately and after all of the other command-line flags. If you actually have a script file called "-" (for some insane reason), you can invoke it as "expect ./-" to get Expect to understand that it really is the name of a script file.

Here are two example invocations of Expect from the shell:

% expect - < command-file
% command-generator | expect -

The first command reads the commands in command-file. The second command runs command-generator and feeds its output to Expect.

Reading commands and data from the same file is not supported. For example, if Expect is reading commands from the standard input, the expect_user command should not be one of the commands read.

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