1 .TH AUTOEXPECT 1 "30 June 1995"
3 autoexpect \- generate an Expect script from watching a session
15 autoexpect watches you interacting with another program and creates an
16 Expect script that reproduces your interactions. For straightline
17 scripts, autoexpect saves substantial time over writing scripts by
18 hand. Even if you are an Expect expert, you will find it convenient
19 to use autoexpect to automate the more mindless parts of interactions.
20 It is much easier to cut/paste hunks of autoexpect scripts together
21 than to write them from scratch. And if you are a beginner, you may
22 be able to get away with learning nothing more about Expect than how
25 The simplest way to use autoexpect is to call it from the command line
26 with no arguments. For example:
30 By default, autoexpect spawns a shell for you. Given a program name
31 and arguments, autoexpect spawns that program. For example:
33 % autoexpect ftp ftp.cme.nist.gov
35 Once your spawned program is running, interact normally. When you
36 have exited the shell (or program that you specified), autoexpect will
37 create a new script for you. By default, autoexpect writes the new
38 script to "script.exp". You can override this with the \-f flag
39 followed by a new script name.
41 The following example runs "ftp ftp.cme.nist.gov" and stores the
42 resulting Expect script in the file "nist".
45 % autoexpect \-f nist ftp ftp.cme.nist.gov
48 It is important to understand that
49 autoexpect does not guarantee a working script because it necessarily
50 has to guess about certain things \- and occasionally it guesses wrong.
51 However, it is usually very easy to identify and fix these problems.
52 The typical problems are:
56 Timing. A surprisingly large number of programs (rn, ksh, zsh,
57 telnet, etc.) and devices (e.g., modems) ignore keystrokes that arrive
58 "too quickly" after prompts. If you find your new script hanging up
59 at one spot, try adding a short sleep just before the previous send.
61 You can force this behavior throughout by overriding the variable
62 "force_conservative" near the beginning of the generated script. This
63 "conservative" mode makes autoexpect automatically pause briefly (one
64 tenth of a second) before sending each character. This pacifies every
67 This conservative mode is useful if you just want to quickly reassure
68 yourself that the problem is a timing one (or if you really don't care
69 about how fast the script runs). This same mode can be forced before
70 script generation by using the \-c flag.
72 Fortunately, these timing spots are rare. For example, telnet ignores
73 characters only after entering its escape sequence. Modems only
74 ignore characters immediately after connecting to them for the first
75 time. A few programs exhibit this behavior all the time but typically
76 have a switch to disable it. For example, rn's \-T flag disables this
79 The following example starts autoexpect in conservative
86 The \-C flag defines a key to toggle conservative mode.
87 The following example starts autoexpect (in non-conservative
88 mode) with ^L as the toggle. (Note that the ^L is
89 entered literally - i.e., enter a real control-L).
95 The following example starts autoexpect in conservative
96 mode with ^L as the toggle.
104 Echoing. Many program echo characters. For example, if you type
105 "more" to a shell, what autoexpect actually sees is:
117 Without specific knowledge of the program, it is impossible to know if
118 you are waiting to see each character echoed before typing the next.
119 If autoexpect sees characters being echoed, it assumes that it can
120 send them all as a group rather than interleaving them the way they
121 originally appeared. This makes the script more pleasant to read.
122 However, it could conceivably be incorrect if you really had to wait
123 to see each character echoed.
127 Change. Autoexpect records every character from the interaction in
128 the script. This is desirable because it gives you the ability to
129 make judgements about what is important and what can be replaced with
132 On the other hand, if you use commands whose output differs from run
133 to run, the generated scripts are not going to be correct. For
134 example, the "date" command always produces different output. So
135 using the date command while running autoexpect is a sure way to
136 produce a script that will require editing in order for it to work.
138 The \-p flag puts autoexpect into "prompt mode". In this mode,
139 autoexpect will only look for the the last line of program output \-
140 which is usually the prompt. This handles the date problem (see
141 above) and most others.
143 The following example starts autoexpect in prompt mode.
149 The \-P flag defines a key to toggle prompt mode. The following
150 example starts autoexpect (in non-prompt mode) with ^P as the toggle.
151 Note that the ^P is entered literally - i.e., enter a real control-P.
157 The following example starts autoexpect in prompt mode with ^P as the toggle.
160 autoexpect \-p \-P ^P
166 flag disables informational messages produced by autoexpect.
170 flag names a quote character which can be used to enter characters
171 that autoexpect would otherwise consume because they are used as toggles.
173 The following example shows a number of flags with quote used to
174 provide a way of entering the toggles literally.
177 autoexpect \-P ^P \-C ^L \-Q ^Q
182 I don't know if there is a "style" for Expect programs but autoexpect
183 should definitely not be held up as any model of style. For example,
184 autoexpect uses features of Expect that are intended specifically for
185 computer-generated scripting. So don't try to faithfully write
186 scripts that appear as if they were generated by autoexpect. This is
189 On the other hand, autoexpect scripts do show some worthwhile things.
190 For example, you can see how any string must be quoted in order to use
191 it in a Tcl script simply by running the strings through autoexpect.
195 "Exploring Expect: A Tcl-Based Toolkit for Automating Interactive Programs"
197 O'Reilly and Associates, January 1995.
199 Don Libes, National Institute of Standards and Technology
204 are in the public domain.
206 appreciate credit if these programs or parts of them are used.