Debian Codegraph @

upstream/debian-unstable/man1/expect_autoexpect.1

raw
1 .TH AUTOEXPECT 1 "30 June 1995"
2 .SH NAME
3 autoexpect \- generate an Expect script from watching a session
4 .SH SYNOPSIS
5 .B autoexpect
6 [
7 .I args
8 ]
9 [
10 .I program args...
11 ]
12 .SH INTRODUCTION
13
14 autoexpect watches you interacting with another program and creates an
15 Expect script that reproduces your interactions. For straightline
16 scripts, autoexpect saves substantial time over writing scripts by
17 hand. Even if you are an Expect expert, you will find it convenient
18 to use autoexpect to automate the more mindless parts of interactions.
19 It is much easier to cut/paste hunks of autoexpect scripts together
20 than to write them from scratch. And if you are a beginner, you may
21 be able to get away with learning nothing more about Expect than how
22 to call autoexpect.
23
24 The simplest way to use autoexpect is to call it from the command line
25 with no arguments. For example:
26
27 % autoexpect
28
29 By default, autoexpect spawns a shell for you. Given a program name
30 and arguments, autoexpect spawns that program. For example:
31
32 % autoexpect ftp ftp.cme.nist.gov
33
34 Once your spawned program is running, interact normally. When you
35 have exited the shell (or program that you specified), autoexpect will
36 create a new script for you. By default, autoexpect writes the new
37 script to "script.exp". You can override this with the \-f flag
38 followed by a new script name.
39
40 The following example runs "ftp ftp.cme.nist.gov" and stores the
41 resulting Expect script in the file "nist".
42 .nf
43
44 % autoexpect \-f nist ftp ftp.cme.nist.gov
45
46 .fi
47 It is important to understand that
48 autoexpect does not guarantee a working script because it necessarily
49 has to guess about certain things \(en and occasionally it guesses wrong.
50 However, it is usually very easy to identify and fix these problems.
51 The typical problems are:
52 .RS
53 .TP 4
54 \(bu
55 Timing. A surprisingly large number of programs (rn, ksh, zsh,
56 telnet, etc.\&) and devices (e.g., modems) ignore keystrokes that arrive
57 "too quickly" after prompts. If you find your new script hanging up
58 at one spot, try adding a short sleep just before the previous send.
59
60 You can force this behavior throughout by overriding the variable
61 "force_conservative" near the beginning of the generated script. This
62 "conservative" mode makes autoexpect automatically pause briefly (one
63 tenth of a second) before sending each character. This pacifies every
64 program I know of.
65
66 This conservative mode is useful if you just want to quickly reassure
67 yourself that the problem is a timing one (or if you really don't care
68 about how fast the script runs). This same mode can be forced before
69 script generation by using the \-c flag.
70
71 Fortunately, these timing spots are rare. For example, telnet ignores
72 characters only after entering its escape sequence. Modems only
73 ignore characters immediately after connecting to them for the first
74 time. A few programs exhibit this behavior all the time but typically
75 have a switch to disable it. For example, rn's \-T flag disables this
76 behavior.
77
78 The following example starts autoexpect in conservative
79 mode.
80 .nf
81
82 autoexpect \-c
83
84 .fi
85 The \-C flag defines a key to toggle conservative mode.
86 The following example starts autoexpect (in non-conservative
87 mode) with ^L as the toggle. (Note that the ^L is
88 entered literally \(en i.e., enter a real control-L).
89 .nf
90
91 autoexpect \-C ^L
92
93 .fi
94 The following example starts autoexpect in conservative
95 mode with ^L as the toggle.
96 .nf
97
98 autoexpect \-c \-C ^L
99
100 .fi
101 .TP
102 \(bu
103 Echoing. Many program echo characters. For example, if you type
104 "more" to a shell, what autoexpect actually sees is:
105 .nf
106
107 you typed 'm',
108 computer typed 'm',
109 you typed 'o',
110 computer typed 'o',
111 you typed 'r',
112 computer typed 'r',
113 ...
114 .fi
115
116 Without specific knowledge of the program, it is impossible to know if
117 you are waiting to see each character echoed before typing the next.
118 If autoexpect sees characters being echoed, it assumes that it can
119 send them all as a group rather than interleaving them the way they
120 originally appeared. This makes the script more pleasant to read.
121 However, it could conceivably be incorrect if you really had to wait
122 to see each character echoed.
123
124 .TP
125 \(bu
126 Change. Autoexpect records every character from the interaction in
127 the script. This is desirable because it gives you the ability to
128 make judgements about what is important and what can be replaced with
129 a pattern match.
130
131 On the other hand, if you use commands whose output differs from run
132 to run, the generated scripts are not going to be correct. For
133 example, the "date" command always produces different output. So
134 using the date command while running autoexpect is a sure way to
135 produce a script that will require editing in order for it to work.
136
137 The \-p flag puts autoexpect into "prompt mode". In this mode,
138 autoexpect will only look for the last line of program output \-
139 which is usually the prompt. This handles the date problem (see
140 above) and most others.
141
142 The following example starts autoexpect in prompt mode.
143 .nf
144
145 autoexpect \-p
146
147 .fi
148 The \-P flag defines a key to toggle prompt mode. The following
149 example starts autoexpect (in non-prompt mode) with ^P as the toggle.
150 Note that the ^P is entered literally \(en i.e., enter a real control-P.
151 .nf
152
153 autoexpect \-P ^P
154
155 .fi
156 The following example starts autoexpect in prompt mode with ^P as the toggle.
157 .nf
158
159 autoexpect \-p \-P ^P
160
161 .fi
162 .RE
163 .SH OTHER FLAGS
164 The
165 .B \-quiet
166 flag disables informational messages produced by autoexpect.
167
168 The
169 .B \-Q
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.
172
173 The following example shows a number of flags with quote used to
174 provide a way of entering the toggles literally.
175 .nf
176
177 autoexpect \-P ^P \-C ^L \-Q ^Q
178
179 .fi
180 .SH STYLE
181
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
187 not useful.
188
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.
192
193 .SH SEE ALSO
194 .I
195 "Exploring Expect: A Tcl-Based Toolkit for Automating Interactive Programs"
196 \fRby Don Libes,
197 O'Reilly and Associates, January 1995.
198 .SH AUTHOR
199 Don Libes, National Institute of Standards and Technology
200
201 .B expect
202 and
203 .B autoexpect
204 are in the public domain.
205 NIST and I would
206 appreciate credit if these programs or parts of them are used.
207