Expect

Expect
Login

Introduction

Expect is a tool for automating interactive applications such as telnet, ftp, passwd, fsck, rlogin, tip, etc. Expect really makes this stuff trivial. Expect is also useful for testing these same applications. And by adding Tk, you can also wrap interactive applications in X11 GUIs.

Expect can make easy all sorts of tasks that are prohibitively difficult with anything else. You will find that Expect is an absolutely invaluable tool - using it, you will be able to automate tasks that you've never even thought of before - and you'll be able to do this automation quickly and easily.

More information on Expect is available in the following documents:


Obtaining Expect for UNIX

You can get Expect and the examples from its File manager at SourceForge. Then, at the command line, type:

gunzip expect.tar.gz tar -xvf expect.tar

This will create a directory containing the Expect distribution. Change to that directory and read the README file.

Note: Expect requires Tcl. If you don't already have Tcl, you can download it as source from the Tcl Core web site or as binaries from ActiveState.

The most current snapshots of Expect will be found in the expect fossil repository. Not all snapshots are official releases.

Not all old versions of Expect are available, but some are. The current version is also available this way if you need to refer to it by explicit version.

The sha-256 hash for expect5.45.4.tar.gz is: 49a7da83b0bdd9f46d04a04deec19c7767bb9a323e40c4781f89caf760b92c34

Obtaining Expect for Windows

There is a windows port of Expect available from ActiveState.


Obtaining the examples

The distribution contains many example scripts, including well-known scripts such as multixterm, kibitz, rftp (recursive ftp), passmass, autoexpect and the delicious beer script. All of the substantive examples in the book are included and many of them have man pages themselves. Here's the list of examples.

The best way to obtain the examples is to follow the directions for obtaining Expect (above). Once you have received and unpacked the distribution, you can find the examples in the example directory. You can also retrieve examples, man pages, and web pages individually here although you run the risk of trying an example that depends on a more up-to-date version of Expect than you have installed. (The web pages were all generated from the man pages so there should be no difference in content.)

Here are man pages for some of the examples. (Not all of the examples need man pages but these do.)


Links to related information

The following are some other particularly worthwhile Expect-related links.

DejaGnu is a popular Expect-based framework for testing other programs. If you are starting out and feel overwhelmed by the capabilities of Expect or would just like some guidance on how to structure a test suite, check out DejaGnu. DejaGnu is used by many standards testing organizations.

expy is the Expect library embedded in Python instead of Tcl.

ActiveTcl is an integrated collection of Tcl, Expect, and many other extensions.

More about Exploring Expect

"Exploring Expect" is an excellent resource for learning and using Expect. (Pub: O'Reilly, ISBN 1-56592-090-2) The book contains hundreds of examples and also includes a tutorial on Tcl. Exploring Expect is 602 pages.

Articles, Papers, and Chapters on Expect

Warning: The examples in all of the papers listed below here are archaic. Critical aspects (usually syntax) of both Expect and Tcl have changed since they were written. (It's not that Expect has changed that recently - rather it's because of incredibly slow turnaround by many reviewers, editors, and journals.)

The papers still make interesting reading - just don't study the examples too closely! Fortunately, most of the examples from the papers also accompany the Expect distribution - and all of the online examples are up to date.


History

Expect was conceived of in September, 1987. The bulk of version 2 was designed and written between January and April, 1990. Minor evolution occurred after that until Tcl 6.0 was released. At that time (October, 1991) approximately half of Expect was rewritten for version 3. See the HISTORY file for more information. The HISTORY file is included with the Expect distribution.

Around January 1993, an alpha version of Expect 4 was introduced. This included Tk support as well as a large number of enhancements. A few changes were made to the user interface itself, which is why the major version number was changed. A production version of Expect 4 was released in August 1993.

In October 1993, an alpha version of Expect 5 was released to match Tcl 7.0. A large number of enhancements were made, including some changes to the user interface itself, which is why the major version number was changed (again). The production version of Expect 5 was released in March '94.

In the summer of 1999, substantial rewriting of Expect was done in order to support Tcl 8.2. (Expect was never ported to 8.1 as it contained fundamental deficiencies.) This included the creation of an exp-channel driver and object support in order to take advantage of the new regexp engine and UTF/Unicode. The user interface is highly but not entirely backward compatible. See the NEWS file in the distribution for more detail.

There are important differences between Expect 3, 4, and 5. See the CHANGES.* files in the distribution if you want to read about the differences. Expect 5.30 and earlier versions have ceased development and are not supported. However, the old code is available from http://expect.nist.gov/old.

The Expect book became available in January '95. It describes Expect 5 as it is today, rather than how Expect 5 was when it was originally released. Thus, if you have not upgraded Expect since before getting the book, you should upgrade now.

Historical notes on Tcl and Tk according to John Ousterhout

I got the idea for Tcl while on sabbatical leave at DEC's Western Research Laboratory in the fall of 1987. I started actually implementing it when I got back to Berkeley in the spring of 1988; by summer of that year it was in use in some internal applications of ours, but there was no Tk. The first external releases of Tcl were in 1989, I believe. I started implementing Tk in 1989, and the first release of Tk was in 1991.


Even more links

Books

Practical Programming with Tcl and Tk by Brent Welch, Prentice Hall, 1995, ISBN 0-13-182007-9.

Graphical Applications with Tcl and Tk by Eric F. Johnson, M&T Books, 1996, ISBN 1-55851-471-6 - Covers cross-platform development with Tcl and Tk on Windows and UNIX.

There are too many books to list all of them here. See the Tcl FAQ for a bigger list.

FAQs

Miscellaneous

Pages that are particularly worthwhile but don't fall in the preceding categories.


Last edited: Mon Aug 3 12:43:13 EDT 2009

Technical Contact: Don Libes

The National Institute of Standards and Technology (NIST) is an agency of the U.S. Department of Commerce.
Privacy policy / security notice / accessibility statement / Disclaimer / Freedom of Information Act (FOIA) / No Fear Act Data / ExpectMore.gov (performance of federal programs) / NIST Information Quality Standards

Disclaimer/Privacy