More On Terminal Modes (Or The -reset Flag)
The interact command puts the terminal into raw mode so that all characters can pass uninterpreted to the spawned process. When a pattern matches, actions are executed in raw mode as well. Usually this works well. Most actions do not depend on the terminal mode. For example, the following commands are all terminal-mode independent:
set a [expr 8*$a] send "k\r" send_user "hello\n"
You may be surprised that the last command works correctly since it includes a newline. Normally, newlines become linefeeds in raw mode. However, the send_user command automatically translates newlines to carriage-return linefeed sequences when the terminal is in raw mode. (See Chapter 8 (p. 197) if you want to disable this.) Thus, you can write such commands and not worry about the mode.
Some commands are mode dependent. Here are three example commands, each of which is mode dependent.
system cat file exec kill -STOP 0 expect -re "(.*)\n"
The first command (”system cat ...“) executes a program that writes directly to the standard input and output. The program assumes the terminal is in cooked mode and will misbehave if it is not. A common symptom of this misbehavior is displayed in the following output:
this is line one
this is line two
this is line three
and so on
The next command (exec kill ...) suspends the Expect process, placing the user back in the original shell. Shells that do not force cooked mode will behave incorrectly, leaving processes to run in raw ...