autoexpect - Man Page

generate an Expect script from watching a session

Synopsis

autoexpect [ args ] [ program args... ]

Introduction

autoexpect watches you interacting with another program and creates an Expect script that reproduces your interactions.  For straightline scripts, autoexpect saves substantial time over writing scripts by hand.  Even if you are an Expect expert, you will find it convenient to use autoexpect to automate the more mindless parts of interactions. It is much easier to cut/paste hunks of autoexpect scripts together than to write them from scratch.  And if you are a beginner, you may be able to get away with learning nothing more about Expect than how to call autoexpect.

The simplest way to use autoexpect is to call it from the command line with no arguments.  For example:

% autoexpect

By default, autoexpect spawns a shell for you.  Given a program name and arguments, autoexpect spawns that program.  For example:

% autoexpect ftp ftp.cme.nist.gov

Once your spawned program is running, interact normally.  When you have exited the shell (or program that you specified), autoexpect will create a new script for you.  By default, autoexpect writes the new script to "script.exp".  You can override this with the -f flag followed by a new script name.

The following example runs "ftp ftp.cme.nist.gov" and stores the resulting Expect script in the file "nist".

	% autoexpect -f nist ftp ftp.cme.nist.gov

It is important to understand that autoexpect does not guarantee a working script because it necessarily has to guess about certain things - and occasionally it guesses wrong. However, it is usually very easy to identify and fix these problems. The typical problems are:

Other Flags

The -quiet flag disables informational messages produced by autoexpect.

The -Q flag names a quote character which can be used to enter characters that autoexpect would otherwise consume because they are used as toggles.

The following example shows a number of flags with quote used to provide a way of entering the toggles literally.

	autoexpect -P ^P -C ^L -Q ^Q

Style

I don't know if there is a "style" for Expect programs but autoexpect should definitely not be held up as any model of style.  For example, autoexpect uses features of Expect that are intended specifically for computer-generated scripting.  So don't try to faithfully write scripts that appear as if they were generated by autoexpect.  This is not useful.

On the other hand, autoexpect scripts do show some worthwhile things. For example, you can see how any string must be quoted in order to use it in a Tcl script simply by running the strings through autoexpect.

See Also

"Exploring Expect: A Tcl-Based Toolkit for Automating Interactive Programs" by Don Libes, O'Reilly and Associates, January 1995.

Author

Don Libes, National Institute of Standards and Technology

expect and autoexpect are in the public domain. NIST and I would appreciate credit if these programs or parts of them are used.

Info

30 June 1995