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 interpreter Command

When Expect runs interactively, it prompts for a command. The command is evaluated and Expect prompts for another command. This continues, typically, until you press ^D or enter the exit command. It is possible to kill Expect in a myriad of other ways, such as by sending it a kill signal or closing the standard input but I will not describe these further here.

When Expect is interactively prompting for commands, it is actually running a command called interpreter. The interpreter command can be invoked just like any command. It takes no arguments and is invoked simply as:

interpreter

The interpreter command is often used just for experimenting with Expect. For example, you might write a dozen or so lines of code at a time and then want to test them out even though the script is not complete. Rather than just having the script exit, you can stick in an interpreter command at the end. When the script is executed, you will get control so you can see what has been accomplished and can play around a little more.

With a small modification to any script, you can use interpreter as part of a general strategy for catching any errors. Nest any executable commands at the top level inside a catch command. This technique is ideal once you have a complete script but are still running across occasional errors. Make your script look like this:

# define all procedures proc first { . . . proc second { . . . proc third { . . . # call first procedure that starts things rolling ...
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