Problem: When using Expect.pm, fatal errors generated by the program being
executed do not seem distinguishable from other output by the program.
Here is a pruned example to demonstrate the problem:
my $object = Expect->spawn("program"); # 1
my $error = ($object->expect(30, 'password:'))[1]; # 2
die "$error\n" if ($error); # 3
print $object "incorrectpassword\r"; # 4
$object->soft_close(); # 5
An error in line 2 caused by a problem with the expect command will go
to STDERR. An error generated by 'program'--such as will be generated
after sending the incorrect password at line 4--will go to STDOUT, not
STDERR, which is also where any data resulting from a valid run of 'program'
will go.
Is there some way I can separate the output of 'program' based upon the
status of 'program'? If there is any mention of such behavior in the
Expect docs then it was probably in the section that was too dense for
me, so please elaborate instead of pointing me to them, as I have read
quite a few times.