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.

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.