ptg10805159
720 Pseudo Terminals Chapter 19
terminal
device driver PTY master PTY slave
terminal
line discipline
terminal
line discipline
kernel
scriptprocess
script
file
fork
exec
login
shell
(sleeping)
forkexec shell
stdout
stderr
stdin
user at a
terminal
Figure 19.5 Thescriptprogram
After developing the generalptyprogram in Section 19.5, we’ll see that a trivial
shell script turns it into a version of thescriptprogram.
expectProgram
Pseudo terminals can be used to drive interactive programs in noninteractive modes.
Numerous programs arehard-wired to requireaterminal to run. One example is the
passwd( 1 )command, which requires that the user enter a password in response to a
prompt.
Rather than modify all the interactive programs to support a batch mode of
operation, a better solution is to provide a way to drive any interactive program from a
script. Theexpectprogram[Libes 1990, 1991, 1994]provides a way to do this. It uses
pseudo terminals to run other programs, similar to theptyprogram in Section 19.5.
But expectalso provides a programming language to examine the output of the
program being run to make decisions about what to send the program as input. When
an interactive program is being run from a script, we can’t just copy everything from the
script to the program, and vice versa. Instead, we have to send the program some
input, look at its output, and decide what to send it next.