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