interact
-complete description
summary
of options
Gives control of the current
process to the user, so that keystrokes are sent to the current process,
and the stdout and stderr of the current process are returned.
String-body pairs may be
specified as arguments, in which case the body is executed when the corresponding
string is entered. (By default, the string is not sent to the current
process.) The interpreter command is assumed, if the final body is missing.
If the arguments to the entire
interact statement require more than one line, all the arguments may be
“braced” into one so as to avoid terminating each line with a backslash.
In this one case, the usual Tcl substitutions will occur despite the braces.
For example, the following
command runs interact with the following string-body pairs defined: When
^Z is pressed, Expect is suspended. (The -reset flag restores the
terminal modes.) When ^A is pressed, the user sees “you typed a control-A”
and the process is sent a ^A. When $ is pressed, the user sees the
date. When ^C is pressed, Expect exits. If “foo” is entered,
the user sees “bar”. When ~~ is pressed, the Expect interpreter runs
interactively.
set CTRLZ \032
interact {
reset $CTRLZ {exec
kill -STOP [pid]}
\001 {
send_user “you typed ontrol-A\n”;
send “\001”
}
$ {
send_user “The date is \
[exec date].”}
\003 exit
foo {
send_user “bar”
}
~~
}
In string-body pairs,
strings are matched in the order they are listed as arguments. Strings
that partially match are not sent to the current process in anticipation
of the remainder coming. If characters are then entered such that
there can no longer possibly be a match, only the part of the string will
be sent to the process that cannot possibly begin another match.
Thus, strings that are substrings of partial matches can match later, if
the original strings that was attempting to be match ultimately fails.
By default, string matching
is exact with no wildcards. (In contrast, the expect
command uses glob-style patterns by default.)
For example, the following
statement could be used to autologout users who have not typed anything
for an hour but who still get frequent system messages:
interact
-input $user_spawn_id
timeout 3600
return -output $spawn_id
If the pattern is the
keyword null, and nulls are allowed (via the remove_nulls command), the
corresponding body is executed if a single ASCII 0 is matched. It
is not possible to match 0 bytes via glob or regexp patterns.
String-body pairs can be
used as a shorthand for avoiding having to enter the interpreter and execute
commands interactively. The previous terminal mode is used while
the body of a string-body pair is being executed.
For speed, actions execute
in raw mode by default.
summary
of options
This material is excerpted
from the O'Reilly book "Exploring Expect" by Don Libes, and can also be
found in the manpage on many UNIX platforms.
|