The Expect Home Page

发表于:2007-07-04来源:作者:点击数: 标签:
This page describes Expect and several othertools that can be found at this site. First, Expect . . . Introduction Expect is a tool for automating interactive applications such astelnet, ftp, passwd, fsck, rlogin, tip, etc. Expect really ma
This page describes Expect and several othertools that can be found at this site. First, Expect . . .


Introduction

Expect is a tool for automating interactive applications such astelnet, ftp, passwd, fsck, rlogin, tip, etc. Expect really makes thisstuff trivial. Expect is also useful for testing these sameapplications. And by adding Tk, you can also wrap interactiveapplications in X11 GUIs.

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

Ok - enough of the hype. More information on Expect isavailable in the following documents:

  • Download Expect for UNIX or Expect for Windows now!
  • Exploring Expect isthe book on Expect.
  • Expect FAQ (Frequently Asked Questions List)
  • Examples that come with Expect.
  • Contributed scripts in the public Expect archive
  • TheExpect README is the same README file that comes withExpect. The README has lots of valuable information that has yet tobe incorporated into this home page. It includes a description of thesoftware distribution, where and how to send bug reports, how to getsupport or classes, and some other background information.
  • History about the development of Expect and differences between versions. The current version of Expect is
  • 5.43.0, created Mon Feb 07 09:19:54 PM EST 2005.
  • Links to related information

Obtaining Expect for UNIX

You can get Expect and the examples from expect.nist.gov as expect.tar.Z or expect.tar.gz.The gz file is preferrable simply because it is quicker to download.However, if you have no idea what to do with a gz file once you've gotit, just transfer the Z version of the distribution. Then, at thecommand line, type:

 uncompress expect.tar.Z
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 Developer Xchange web site or as binaries from ActiveState.

The most current snapshots of Expect will be found in the SourceForge CVS repository. Not allsnapshots 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 md5 hash for expect.tar.gz (also available by explicit version as expect-5.43.0.tar.gz) is: 230400129630335b3060a42f66fec11d

Obtaining Expect for Windows

There are two different ports of Expect for Windows:

Author Location Other notes
ActiveState ActiveState Native port, based on Expect V5.39 and Tcl 8.4+, runs on XP/NT/2k. Available with support or as part of ASPN Tcl.
Gordon Chaffee http://bmrc.berkeley.edu/people/chaffee/tcltk.html Native port, based on Expect V5.21
Rob Savoye http://www.gnu.org/software/dejagnu A cygwin-based port (i.e., feels like UNIX), version unknown, bundled with DejaGnus

[The following statement is required per NIST policy] Byselecting these links, you will be leaving NIST webspace. We haveprovided these links to other web sites because they may haveinformation that would be of interest to you. No inferences should bedrawn on aclearcase/" target="_blank" >ccount of other sites being referenced, or not, from thispage. There may be other web sites that are more appropriate for yourpurpose. NIST does not necessarily endorse the views expressed, orconcur with the facts presented on these sites. Further, NIST does notendorse any commercial products that may be mentioned on these sites.

Obtaining the examples

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

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

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

  • autoexpect
  • cryptdir/decryptdir
  • dislocate
  • kibitz
  • mkpasswd
  • multixterm
  • passmass
  • tknewsbiff
  • unbuffer
  • xkibitz

Links to related information

[The following statement is required per NIST policy] Byselecting these links, you will be leaving NIST webspace. We haveprovided these links to other web sites because they may haveinformation that would be of interest to you. No inferences should bedrawn on account of other sites being referenced, or not, from thispage. There may be other web sites that are more appropriate for yourpurpose. NIST does not necessarily endorse the views expressed, orconcur with the facts presented on these sites. Further, NIST does notendorse any commercial products that may be mentioned on these sites.

The following are some other particularly worthwhile Expect-relatedlinks.

  • DejaGnuis a popular Expect-based framework for testing other programs. Ifyou are starting out and feel overwhelmed by the capabilities ofExpect or would just like some guidance on how to structure a testsuite, check out DejaGnu. DejaGnu is used by many standards testingorganizations.
  • WINTERPis a rapid prototyping, development and deliveryenvironment for GUI-based applications on Unix platforms. WINTERP usesLisp instead of Tcl.
  • expy is the Expect library embedded in Python instead of Tcl.
  • ICE Tcl/Tk is a truecompiler for Tcl/Tk. It also includes support for Expect.
  • ftp.procplace.com/pub/tcl/neosoft/neotcl/neotcl7.5.tar.gz">ActiveTclis an integrated collection of Tcl, Expect, and many other extensions.

More about Exploring Expect

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

NIST policy is to avoid endorsements for commercial products ororganizations. Hence this page provides no link for the publisheror any further information about how to obtain the book.

Articles, Papers, and Chapters on Expect

  • Fisher, David L., Advanced Programming in Expect: A Bulletproof Interface, November, 1999.
  • Libes, D., "Expect", Tcl/Tk Extensions, ed, Mark Harrison, O'Reilly& Associates, Inc., 1997.
  • Libes, D., "Writing a Tcl Extension in Only ... 7 Years" (HTML,PDF),PostScript,Proceedings of theFifth Annual Tcl/Tk Workshop '97, Boston, MA, July 14-7, 1997.Winner of Best Paper Award at conference.
  • Libes, D., "Tcl/Tk-basedAgents for Mail and News Notification -- or -- A Tale of TwoBiffs", Software - Practice & Experience, John Wiley & Sons, West Sussex,England, to appear. [This paper isn't really about Expect per se.However, a large section of the paper is on tknewsbiff which is one ofthe Expect examples.]
  • Friesenhahn, B., "Expect Offers UNIX Scripting", Byte Magazine, April 1997.
  • Libes, D., Automation andTesting of Interactive Character Graphic Programs, Software - Practice and Experience, Vol. 27(2), p 123-137,February 1997.
  • Libes, D., "How to Avoid LearningExpect -- or -- Automating Automating Interactive Programs" (PDF, PostScript),Proceedings of the Tenth USENIX System Administration Conference (LISAX), Chicago, IL, September 30 - October 4, 1996.
  • Libes, D., "Writing CGI Scripts in Tcl" (PDF, PostScript), Proceedingsof the Fourth Annual Tcl/Tk Workshop '96, Monterey, CA, July 10-13,1996. [This paper isn't really about Expect per se. However, it doesshow a nice example of Expect in a CGI script for the purpose ofchanging passwords through web pages. The complete form/script can befound in the source distribution.] Winner of Best PresentationAward at conference.
  • Libes, D., TerminalEmulation for Automation and Testing of Character Graphic Programs: ACode Walkthrough, Proceedings of The 21st Annual Trenton ComputerFestival (TCF '96), Trenton, NJ, April 21-22, 1996 - a much longer andmore detailed version of the SP&E paper (above) [I submitted thisoriginally to SP&E and they cut it down to what ultimately appeared butrecommended that this version was still worth publishing elsewhere -hence this second publication.]
  • Faught, D., Testing Interactive Programs, Software QAMagazine, Vol. 3, No. 1, February 1996.
  • Fischer, P., The Expect Programand Other Skunkware Tools, SCO World, February, 1996.
  • Libes, D., HandlingPasswords with Security and Reliability in Background Processes(PostScript,PDF),Proceedings of the 1994 USENIX LISA VIII Conference, San Diego, CA,September 19-23, 1994 - Simple techniques to allow secure handling ofpasswords in background processes.
  • Morse, W., A Tcl/Tk and Expect Tutorial, World WideTechnology Conference, Houston, TX, December 1, 1994. Winner ofBest Paper Award at conference.
  • Libes, D., Ouch, Those Programs Are Painful, ORA.COM,O'Reilly & Associates, Inc., Fall '94.
  • Libes, D., ADebugger for Tcl Applications, Proceedings of the 1993 Tcl/TkWorkshop, Berkeley, CA, June 10-11, 1993 - A presentation of the Tcldebugger - theory, implementation, and use.

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

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

  • McNutt, D., Expect, January, 1994,UNIX Review, Vol. 12, No. 6, January 1994 - Introductory article.
  • Libes, D., X Wrappersfor Non-Graphic Interactive Programs, Proceedings of Xhibition'94, San Jose, CA, June 20-24, 1994 - Discussion of wrappinginteractive programs with Tk.
  • Dichter, C., Surviving SoftwareTesting, UNIX Review, pps 29-36, V11, #2, Feb 1993.
  • Libes, D., Kibitz -Connecting Multiple Interactive Programs Together, Software -Practice & Experience, Vol. 23, No. 5, May 1993 - Paper on connectingmultiple interactive programs together using Expect.
  • Libes, D., Obfuscated C andOther Mysteries, Chapter 36 ("Expect"), John Wiley & Sons, ISBN0-471-57805-3, January 1993 - An explanation of some of the moreinteresting source code to an early version of Expect.
  • Libes, D., Automating Interactive Applications in the NetworkEnvironment, International Communications Association Journal, May17, 1992.
  • Smith, B., Software Corner, Byte Magazine, 1992.
  • Caffrey, P., User Interfaces and Automating Computer HumanInteraction, MSc. Thesis, Amdahl Ireland Ltd., 1992.
  • Woodson, B., Regression Testing Using Expect, How ToImplement Quality In Software Conference, Santa Clara Valley SoftwareQuality Association, June 29, 1991.
  • Libes, D., RegressionTesting and Conformance Testing Interactive Programs, Proceedingsof the Summer 1992 USENIX Conference, San Antonio, TX, June 8-12, 1992- Discussion of regression and conformance testing. If you areinterested in this, you should also check out DejaGnu.
  • Libes, D., Expect:Scripts for Controlling Interactive Programs, Computing Systems,Vol. 4, No. 2, University of California Press Journals, 1991 - A niceoverview with a balance of example scripts and explanations.
  • Libes, D., Implementor'sNotebook: Implementing a Trap Command, C Users Journal, Vol. 9,No. 3, R&D Publications, Lawrence, KS, January, March, 1991 -Explanation of how Expect's trap command was implemented.
  • Libes, D., Implementor'sNotebook: Expect, C Users Journal, Vol. 9, No. 1, R&DPublications, Lawrence, KS, January, January, 1991 - Explanation ofsome of the more interesting source code to an early version of Expect(an improved version of this appeared later as Obfuscated C and OtherMysteries, Chapter 36 ("Expect").
  • Anderson, D., "Expect", January, 1991, SunExpert Magazine,Vol. 2, No. 1, January 1991 - Introductory article.
  • Libes, D., Using Expectto Automate System Administration Tasks, Proceedings of the 1990USENIX Large Systems Administration Conference (LISA) IV, ColoradoSprings, CO, October 17-19, 1990 - Examples and discussion,specifically aimed at system administrators.
  • Libes, D., Expect:Curing Those Uncontrollable Fits of Interaction, Proceedings ofthe Summer 1990 USENIX Conference, Anaheim, CA, June 11-15, 1990 -Discussion of Expect's implementation, philosophy, and someperformance notes.

History

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

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

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

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

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

The Expect book became available in January '95. It describes Expect5 as it is today, rather than how Expect 5 was when it was originallyreleased. Thus, if you have not upgraded Expect since before gettingthe 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'sWestern Research Laboratory in the fall of 1987. I started actuallyimplementing it when I got back to Berkeley in the spring of 1988; bysummer of that year it was in use in some internal applications ofours, but there was no Tk. The first external releases of Tcl were in1989, I believe. I started implementing Tk in 1989, and the firstrelease of Tk was in 1991.


Other useful software at this site

  • NICS - A service to allowcollaborative management of identifiers.
  • cgi.tcl- A comprehensive library for creating Tcl-based CGI scripts. cgi.tclsupports tables, cookies, file upload, Expect, Tcl applets, Java, etc,etc.
  • tcl-debug- A Tcl debugger. Provides traditional debugging capabilities to anyTcl script. Built in to Expect but it works with any Tcl extensionincluding Tk. Can be dynamically loaded.
  • tkbiff - allowsarbitrary commands (play audio clip, metamail, etc) to be executedupon mail reception. (If you like xbiff++ but wish it were moreflexible or more portable, then you'll like tkbiff.) tkbiff isflexible enough that you can make it do anything. Default behavior:fast and convenient access to new email using very little screen realestate.
  • md5pure and sha1pure - Computesmd5 and sha1 message digests using only core Tcl commands. Surprisingly fast.(Surprised me anyway.)
  • FAQbuilder - A very easy-to-use FAQ builder. Simplifies maintenanceof hyperlinks, automatically repeats the questions with links to theanswers, automatically produces different formats (currently only textand html supported), etc.
  • Stopwatch - Alittle stopwatch - just right for helping you get the timing downwhile practicing a talk. Provided both as an applet and a standaloneTk script.

Even more links

[The following statement is required per NIST policy] Byselecting these links, you will be leaving NIST webspace. We haveprovided these links to other web sites because they may haveinformation that would be of interest to you. No inferences should bedrawn on account of other sites being referenced, or not, from thispage. There may be other web sites that are more appropriate for yourpurpose. NIST does not necessarily endorse the views expressed, orconcur with the facts presented on these sites. Further, NIST does notendorse any commercial products that may be mentioned on these sites.

The following links have nothing specifically to do with Expectbut may be significant in their value to Expect users nonetheless:

Books

  • Tcl and the Tk Toolkit by John Ousterhout, Addison-Wesley, 1994,ISBN 0-201-63337-X - the seminal book on Tcl and Tk.
  • PracticalProgramming with Tcl and Tk by Brent Welch, Prentice Hall, 1995, ISBN0-13-182007-9.
  • GraphicalApplications with Tcl and Tk by Eric F. Johnson, M&T Books, 1996,ISBN 1-55851-471-6 - Covers cross-platform development with Tcl and Tkon Windows and UNIX.
  • There are too many books to list all of them here. See the TclFAQ for a bigger list.

FAQs

  • Expect FAQ
  • Tcl FAQ Part 1: General questions
  • Tcl FAQ Part 2: Bibliography, maillists, etc.
  • Tcl FAQ Part 3: Misc questions
  • Tcl FAQ Part 4: Applications
  • Tcl FAQ Part 5: Extensions
  • Tcl Windows FAQ

Miscellaneous

Pages that are particularly worthwhile but don't fall in the precedingcategories.
  • Tcler's Wiki - Collaborative web pages on Tcl
  • Mark Roseman's offer to host Project Forum sites for use by open source Tcl/Tk projects
  • A Wiki-like site devoted to improving Tk so it can be used to build commercial-class GUIs
  • Newsgroups

    • comp.lang.tcl - Expect discussion/questions are encouraged in this newsgroup.
    • comp.lang.tcl.announce
  • ActiveState's Tcl page

Last edited: Tue Feb 8 16:45:38 EST 2005Technical Contact: Don Libes
National Institute of Standards and Technology Disclaimer/Privacy

原文转自:http://www.ltesting.net