1 |
578 |
markom |
This file describes the changes from Expect 3 to Expect 4.
|
2 |
|
|
|
3 |
|
|
The improvements that people will find most interesting are:
|
4 |
|
|
|
5 |
|
|
1) Expect version 4 is designed to work with Tcl 6.7 and Tk 3.2.
|
6 |
|
|
(Earlier versions of Expect will not work with Tcl 6.7)
|
7 |
|
|
Expect can now be layered in with any Tcl program.
|
8 |
|
|
Note that in Tk, Expect's send command is called "exp_send".
|
9 |
|
|
(It used to be called "send_spawn" but this bit the dust.)
|
10 |
|
|
2) A debugger is provided.
|
11 |
|
|
3) The interact command has been totally rewritten and supports regular
|
12 |
|
|
expressions, timeout/eof patterns, and a number of other new things.
|
13 |
|
|
4) The default behavior of ^C (SIGINT) is exit whether or not you are in
|
14 |
|
|
a read.
|
15 |
|
|
5) Expect uses "sane" terminal parameters by default, allowing scripts
|
16 |
|
|
to work the same whether inside emacs shell mode or not. (See man
|
17 |
|
|
page on "spawn" for more info.)
|
18 |
|
|
6) All the hard parts of the installation process are automated. This
|
19 |
|
|
was done primarily by Rob Savoye at Cygnus. Thank you, Rob!
|
20 |
|
|
7) It is now possible to buy a support contract for Expect from Cygnus.
|
21 |
|
|
|
22 |
|
|
The changes that people will find most annoying are:
|
23 |
|
|
|
24 |
|
|
1) send now only sends a single string. (It used to send any number of
|
25 |
|
|
strings with spaces jammed in between.)
|
26 |
|
|
2) getpid was renamed pid.
|
27 |
|
|
3) interact's -flush was renamed -nobuffer (much more descriptive).
|
28 |
|
|
4) interact now runs all actions in raw mode unless the flag -reset
|
29 |
|
|
is used. -f and -F are ignored. send automatically understands
|
30 |
|
|
how to do the right thing. The most likely thing to watch out for
|
31 |
|
|
are actions like "exec kill -STOP 0" which almost certainly need
|
32 |
|
|
the -reset flag.
|
33 |
|
|
5) argv0 is initialized to script name. argv no longer contains it.
|
34 |
|
|
argc is initialized [llength $argv]. This follows new Tcl style.
|
35 |
|
|
|
36 |
|
|
All differences are described in the man page. Some of the less
|
37 |
|
|
significant differences are described in the HISTORY file. The
|
38 |
|
|
debugger is described in a separate document (see the README).
|
39 |
|
|
|
40 |
|
|
This version also introduces one incompatibility that may require
|
41 |
|
|
changes to scripts. While this may initially annoy you, the final
|
42 |
|
|
result will simplify the process of writing scripts. Namely:
|
43 |
|
|
|
44 |
|
|
In version 3, the expect command accepted lists of glob-style patterns
|
45 |
|
|
such as:
|
46 |
|
|
|
47 |
|
|
expect "a\ b c" action
|
48 |
|
|
|
49 |
|
|
where "a b" or "c" would cause action to be executed. The problem
|
50 |
|
|
with this is that the pattern list is hard to write and hard to read.
|
51 |
|
|
Patterns with control-characters, backslashes and dollar signs were
|
52 |
|
|
very difficult to deal with.
|
53 |
|
|
|
54 |
|
|
Regular-expression patterns provide a much simpler solution. Via the
|
55 |
|
|
alternation feature (using a "|") the above pattern can be written as:
|
56 |
|
|
|
57 |
|
|
expect -re "a b|c" action
|
58 |
|
|
|
59 |
|
|
I was concerned about people having a significant investment in code
|
60 |
|
|
that depended on the old syntax but responders to a comp.lang.tcl poll
|
61 |
|
|
about such a change in pattern handling were 100% in favor of it. (I
|
62 |
|
|
even proposed hooks for backward compatibility, but there was no
|
63 |
|
|
interest in it.)
|
64 |
|
|
|
65 |
|
|
Fortunately, most simple things will work as before including:
|
66 |
|
|
|
67 |
|
|
expect foobar
|
68 |
|
|
expect {foobar}
|
69 |
|
|
expect "foobar"
|
70 |
|
|
expect "foo\ bar"
|
71 |
|
|
|
72 |
|
|
However, some things won't work as before. For example, the following
|
73 |
|
|
will behave differently - now the braces will be considered as part of
|
74 |
|
|
the pattern.
|
75 |
|
|
|
76 |
|
|
expect "{foo bar}"
|
77 |
|
|
|
78 |
|
|
Here are examples of patterns in my own code that I had to change:
|
79 |
|
|
|
80 |
|
|
was changed to
|
81 |
|
|
Version 3 pattern list Version 4 pattern
|
82 |
|
|
|
83 |
|
|
{Whois:\ } "Whois: "
|
84 |
|
|
{No\ match} "No match"
|
85 |
|
|
{250*ftp>* 200*ftp>*} -re "2(5|0)0.*ftp>.*"
|
86 |
|
|
{{Press Return to continue*}} "Press Return to continue*"
|
87 |
|
|
{*\r\n*\\\\\r\n} "\r\n*\\\r\n"
|
88 |
|
|
|
89 |
|
|
|
90 |
|
|
|
91 |
|
|
Future Change Alert
|
92 |
|
|
|
93 |
|
|
John Ousterhout has pre-announced a future change in Tcl that may
|
94 |
|
|
affect you. In particular, backslash sequences other than those
|
95 |
|
|
explicitly listed in the Tcl documentation will be handled as if the
|
96 |
|
|
backslash was not present.
|
97 |
|
|
|
98 |
|
|
The likely place this arises is when quoting characters that are
|
99 |
|
|
special to the pattern matcher but not to Tcl.
|
100 |
|
|
|
101 |
|
|
For example in Tcl 6.7, the following command matches a period.
|
102 |
|
|
|
103 |
|
|
expect -re "\."
|
104 |
|
|
|
105 |
|
|
In Tcl 7.0, it will match any character, because Tcl will throw away
|
106 |
|
|
the backslash. If you want to match a period, you will have to say:
|
107 |
|
|
|
108 |
|
|
expect -re "\\."
|
109 |
|
|
or
|
110 |
|
|
expect -re {\.}
|
111 |
|
|
|
112 |
|
|
The following command will find occurrences of this. (It may find
|
113 |
|
|
other things, but it will at least find the problem cases.)
|
114 |
|
|
|
115 |
|
|
egrep '(\\$)|(\\[^][bfnrtv\0-9{}$ ;"])' *.exp
|