Log And Diagnostic State
The log and diagnostic states can be obtained by calling the original commands with the -info
flag. The previous parameters are returned. This is commonly used to establish a temporary state.
For example, a subroutine that must be sure that output to the user is disabled should save and restore the state of log_user
.
proc sub {} { set state [log_user -info] ;# save old state log_user 0 ;# set new state # your code goes here eval log_user $state ;# restore old state }
Notice the final call to restore the old state. It uses eval
in order to support the possibility of a multi-element state. The list of elements will be split in such a way that the command sees them as separate arguments.
The log_user
command is not currently defined to take multiple parameters; however, future expansion is likely so it is a good idea to handle it this way. The log_file
and exp_internal
commands take multiple arguments already.
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.