Logging
It is often useful to write information to files so that you can study it later. You can write log files yourself or you can use Expect’s logging functions.
The commands log_user
, log_file
, and exp_internal
can all be helpful while debugging. These commands can also be controlled indirectly through procedures similar to the puts
example above.
I will summarize what these commands do. The log_user
command controls whether the output of spawned processes is seen. In most scripts, you want to leave this set one way or the other, but it is nice to have the flexibility to turn it off and on during development. The log_user
command is described further in Chapter 7 (p. 171).
The log_file
command is related to the log_user
command. However, log_file
has almost no uses other than for debugging. The log_file
command records everything from a spawned process. Even output suppressed via "log_user 0
" can be recorded. The log_file
command is further described in Chapter 7 (p. 176).
The exp_internal
command is another command that is useful only for debugging. The exp_internal
command enables the printing of internal information, mostly concerning pattern matching. This command was discussed in Chapter7 (p. 161).
In Chapter 17 (p. 379), I described how to use mail to save information. This technique can be very useful because you can get an immediate indication as soon as the mail has been generated. With the log commands, you have to remember to look at the files they create. For example, ...
Get Exploring Expect now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.