Cover by Don Libes

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

O'Reilly logo

Enabling Internal Diagnostics

In long scripts, it is convenient to be able to turn Expect’s internal diagnostics off. You can do this with the command "exp_internal 0“. You can use the exp_internal command to turn the diagnostics off and on as you like. For example, it is common to surround just a small group of commands or even one command with exp_internal commands as you narrow down where the problem lies in a script.

exp_internal 1
expect
exp_internal 0

You may also find it convenient to conditionalize the use of exp_internal. For example, you can set a global variable that controls whether all of the exp_internal commands are actually executed. The following code permits "exp_internal 1" commands in the code to execute only when the variable debug_enable is nonzero. The idea is that this variable is set once—which is much easier than adding or commenting in and out commands scattered throughout a script. (In Chapter 9 (p. 219), I will describe how to get this effect on a script-wide basis without changing the script at all.)

if $debug_enable {exp_internal 1}
expect . . .
exp_internal 0
send . . .
expect . . .
if $debug_enable {exp_internal 1}
send . . .
expect . . .
exp_internal 0

The "exp_internal 0" commands do not have to be conditionalized. It is not an error to execute "exp_internal 0" even if diagnostics have not been enabled. In this case, "exp_internal 0" is just ignored.

An even more convenient way to control diagnostic output is to define procedures such as the following ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required