Hello,
Monks, I am trying to make the expect interact with "units" program. But it does not want to match anything, except qr/.*/ and the $exp->before prints nothing. If you want to test, the units can be obtained from http://www.gnu.org/software/units/
use Expect;
$Expect::Debug = 3; # verbose debug output
$Expect::Log_Stdout = 1; # show chatter for debugging
$Expect::Exp_Internal =1;
my $exp = Expect->spawn("units")
or die "Cannot spawn unit: $!\n";
$exp->log_stdout(1);
$exp->expect(15,
[ qr/you have/i => sub { my $exp = shift;
print "you have";
$exp->send("2 km");
exp_continue; } ],
[ qr/you want/i , sub { my $exp = shift;
print "you want";
$exp->send("m");
exp_continue; }],
[ 'eof', sub { my $exp = shift; print "eof"; print
+$exp->before(); } ],
[ qr/.*/, sub { my $exp = shift;
print $exp->error;
print $exp->before();
} ]
);
The units executed in the terminal will print these
user@dell:~> units
2526 units, 72 prefixes, 56 nonlinear units
You have:
In the log it shows this
spawn id(20): Does `'
match:
pattern #1: -re `(?^i:you have)'? No.
pattern #2: -re `(?^i:you want)'? No.
pattern #3: -eof `'? No.
pattern #4: -re `(?^:.*)'? YES!!
Before match string: `'
Match string: `'
After match string: `'
Matchlist: ()
Calling hook CODE(0x7fd8217449c0)...
Returning from expect successfully.
spawn id(20): accumulator: `'
Closing spawn id(20).
Before match string: `'
Why does it show `' ? what is that string ?
And what is wrong with the code ?
Thanks