Debian Codegraph @

tutorial/3.A.debugging

raw
1 #!/usr/local/bin/perl
2 # This example demonstrates how to use the debugging features in
3 #expect. They're reasonably straghtforward.
4 #
5 # There are 3 basic ways you can debug a script:
6 #
7 # 1. Log_Stdout
8 #
9 # By setting $Expect::Log_Stdout you control whether or not processes
10 #will echo to the screen or not. Having it turned on can be helpful so you
11 #can watch what a process is doing. Alternately, for a process that is already
12 #running you can do $process->log_stdout(1); which will turn on process
13 #output for the process from that instant on. $process->log_stdout(0) will
14 #turn it off.
15 # By default $Expect::Log_Stdout == 1. Initialized handles (discussed
16 #later) may also echo to STDOUT, but they don't do so by default. You have
17 #to manually tell them to echo. You wouldn't want your log file jabbering at
18 #you would you? Anyway, that will make sense later.
19 #
20 # 2. Exp_Internal
21 #
22 # Setting $Exp_Internal=1 (or $process->exp_internal(1)) will output
23 #pattern matching information for expect() calls to STDERR. You can trap
24 #this by doing "perl expect_script.pl 2>debug.out" if you are using any of
25 #the bourne-ish shells. For people who use csh, don't. "exec bash" will take
26 #care of that straightaway. This is handy so program output and debugging output
27 #don't go to the same place.
28 #
29 # 3. Debug
30 #
31 # Setting $Expect::Debug = debug level(or $process->debug(debug level))
32 #will show other stuff, such as pids, output during interaction, and other
33 #miscellaneous output not covered by the above two items. In combination with
34 #Exp_Internal you can capture a lot of good information about what your script
35 #is doing. Debugging info also goes to STDERR.
36 #
37 #
38 # This example will show (lots) of debugging info.
39
40
41 use Expect;
42
43 $Expect::Log_Stdout=1;
44 $Expect::Debug=3;
45 $Expect::Exp_Internal=1;
46
47 # lpc is a bsd printer control program. It's included in every Unix I
48 # deal with.
49 $lpc = Expect->spawn("lpc");
50
51 $lpc->expect(30,"lpc> ") && print $lpc "stat\r";
52
53 $lpc->hard_close();