ptg10805159720 Pseudo Terminals Chapter 19terminal
device driver PTY master PTY slaveterminal
line disciplineterminal
line disciplinekernelscriptprocessscript
filefork
execlogin
shell
(sleeping)forkexec shellstdout
stderrstdinuser at a
terminalFigure 19.5 ThescriptprogramAfter 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.