---

Linux Gazette: Advanced Programming in Expect: A Bulletproof Interface

In the design of automated systems using the Expect
programming language, one of the more difficult hurdles many
programmers encounter is ensuring communication with ill-behaved
connections and remote terminals.
The send_expect procedure
detailed in this article provides a means of ensuring communication
with remote systems and handles editing and rebroadcast of the
command line. Where a programmer would usually send a command line
and then expect the echo from the remote system, this procedure
replaces those lines of code and provides the most reliable
interface I have come across….”

“Communication with local processes (i.e. those running on the
same workstation as the expect process) is typically not
problematic and does not require the solutions detailed in this
article. External processes, however, can create a number of
problems that may or may not affect communication, but will affect
an automated system’s ability to determine the success of the
communication. In cases where it is corrupted, it is not always
immediately obvious: a corrupted command may trigger an error
message, but data which has been corrupted may still be considered
valid and the error would not show up immediately, and may cause a
variety of problems. This is why it is necessary to ensure that the
entire string that is transmitted is properly received echoed by
the remote system.”

“The basic idea of this interface is to send the command string
except for its terminating character (usually, a carriage return)
and look at the echo from the remote system. If the two can be
matched using the regular expressions in the expect clauses, then
the terminating character is sent and transmission is considered
successful. If success cannot be determined, the command line is
cleared instead of being sent, and alternative transmission modes
are used.”

Complete
Story

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends, & analysis