Commit | Line | Data |
---|---|---|
920dae64 AT |
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 | .br | |
13 | .SH INTRODUCTION | |
14 | ||
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 | |
23 | to call autoexpect. | |
24 | ||
25 | The simplest way to use autoexpect is to call it from the command line | |
26 | with no arguments. For example: | |
27 | ||
28 | % autoexpect | |
29 | ||
30 | By default, autoexpect spawns a shell for you. Given a program name | |
31 | and arguments, autoexpect spawns that program. For example: | |
32 | ||
33 | % autoexpect ftp ftp.cme.nist.gov | |
34 | ||
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. | |
40 | ||
41 | The following example runs "ftp ftp.cme.nist.gov" and stores the | |
42 | resulting Expect script in the file "nist". | |
43 | .nf | |
44 | ||
45 | % autoexpect \-f nist ftp ftp.cme.nist.gov | |
46 | ||
47 | .fi | |
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: | |
53 | .RS | |
54 | .TP 4 | |
55 | \(bu | |
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. | |
60 | ||
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 | |
65 | program I know of. | |
66 | ||
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. | |
71 | ||
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 | |
77 | behavior. | |
78 | ||
79 | The following example starts autoexpect in conservative | |
80 | mode. | |
81 | .nf | |
82 | ||
83 | autoexpect \-c | |
84 | ||
85 | .fi | |
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). | |
90 | .nf | |
91 | ||
92 | autoexpect \-C ^L | |
93 | ||
94 | .fi | |
95 | The following example starts autoexpect in conservative | |
96 | mode with ^L as the toggle. | |
97 | .nf | |
98 | ||
99 | autoexpect \-c \-C ^L | |
100 | ||
101 | .fi | |
102 | .TP | |
103 | \(bu | |
104 | Echoing. Many program echo characters. For example, if you type | |
105 | "more" to a shell, what autoexpect actually sees is: | |
106 | .nf | |
107 | ||
108 | you typed 'm', | |
109 | computer typed 'm', | |
110 | you typed 'o', | |
111 | computer typed 'o', | |
112 | you typed 'r', | |
113 | computer typed 'r', | |
114 | ... | |
115 | .fi | |
116 | ||
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. | |
124 | ||
125 | .TP | |
126 | \(bu | |
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 | |
130 | a pattern match. | |
131 | ||
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. | |
137 | ||
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. | |
142 | ||
143 | The following example starts autoexpect in prompt mode. | |
144 | .nf | |
145 | ||
146 | autoexpect \-p | |
147 | ||
148 | .fi | |
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. | |
152 | .nf | |
153 | ||
154 | autoexpect \-P ^P | |
155 | ||
156 | .fi | |
157 | The following example starts autoexpect in prompt mode with ^P as the toggle. | |
158 | .nf | |
159 | ||
160 | autoexpect \-p \-P ^P | |
161 | ||
162 | .fi | |
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 |