Overview

You normally run Expect by invoking the program expect (or expectk if you also want Tk). Expect is a Tcl interpreter with about 40 additional commands. This section briefly describes the most common commands.

The spawn command creates a new process that executes a specified program. It creates a connection to that process so that it is accessible by using other Expect commands.

The send command passes commands to a process started by spawn. It sends strings, just as a user would type if interactively running the spawned program.

The expect command is the heart of the Expect program. It compares the output from one or more spawned processes, looking for a match against a string or pattern. If a match is found, it executes Tcl code associated with the pattern. The patterns can be simple strings, glob-style patterns, or regular expressions. Multiple patterns and actions can be specified.

The interact command passes control of a spawned process back to the user. This allows the user to connect to the process interactively. For example, an Expect script could log a user on to a remote system, start a text editor, then pass control back to the user. Like expect, it per forms pattern matching that allows actions to be performed. In our editor example, the script could watch for a pattern that indicated that the text editor program had exited, then pass control back to the Expect script to automatically perform cleanup and log out the user.

The close command closes the connection to a spawned process. This is not always needed, as Expect closes all open connections when it exits.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset