The Expect Library
In Chapter 2 (p. 68), I mentioned that Tcl provides support for libraries of Tcl procedures. Expect follows the Tcl model. Two directories are provided in which users at your site can create and use publicly-accessible Expect procedures or other data. The directory names are stored in the global variables exp_library and exp_exec_library.
The exp_library directory contains files which are platform-independent. If you have the directory NFS-mounted to multiple computers of different types, all of them can share the same common procedures. In contrast, the exp_exec_library directory is specific to a particular machine (and if necessary, different releases of the operating system).
Although scripts are the most common use for these libraries, non-executable data can be stored there as well. For example, in Chapter 13 (p. 287) I mentioned that cat might need a -u flag. Unfortunately, on other systems, the -u flag imposes a performance penalty. So -u should only be used when it is required. One way to detect this is to spawn a cat process, send a character to it, and see if it echoes. Unfortunately, the failure to echo requires an expect command to timeout, and this can take a relatively long time in a script. To avoid this, Expect executes this test upon installation and leaves a marker behind in the form of a file for which scripts can test. Because the behavior is dependent upon a particular executable (namely, /bin/cat), the marker is stored in exp_exec_library
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access