in reply to How to recieve the exit code of a script executed through Expect ?

I have not looked at the actual source for Expect.pm, but according to the pod info the send method does not indicate that it returns any value.

Perhaps there is a better way, but the only thing that comes to mind is to wrap your called script inside a shell script, which then prints the exit status. You can then use $exp->expect to look at it wrapper.sh:

#! /bin/bash dummp.pl # may need full/relative path here echo $?
modified example:
my $result = $exp->send("exec wrapper.sh"); $exp->expect (5, [qr/1/, sub {<handle failure>}], [qr/0/, sub {<handle success>}], ...); ...

Replies are listed 'Best First'.
Re^2: How to recieve the exit code of a script executed through Expect ?
by daphnaw (Acolyte) on May 06, 2010 at 09:15 UTC
    Hi, the wrapper script didnt help. If I run my script with $exp->exp_internal(1); I see the following output:
    Sending 'exec wrapper.sh\n' to spawn id(3) at /export/home/ana37/utils/linux/perl/site/lib/Expect.pm line 1264 Expect::print('Expect=GLOB(0x1f515338)', 'exec wrapper.sh\x{a}') c +alled at test.pl line 32 In dummy.pl~!!!!!!!!!!!!!!!! ** Installation finished successfully 0 Starting EXPECT pattern matching... at /export/home/ana37/utils/linux/perl/site/lib/Expect.pm line 561 Expect::expect('Expect=GLOB(0x1f515338)', 5, 'ARRAY(0x1f121428)', +'ARRAY(0x1f536fc0)') called at test.pl line 46 spawn id(3): list of patterns: #1: -re `(?-xism:1)' #2: -re `(?-xism:0)' spawn id(3): Does `' match: pattern #1: -re `(?-xism:1)'? No. pattern #2: -re `(?-xism:0)'? No. -1
    so there is no match ...
      There is no match because your perl program prints output. My example only expected the return status as output. Make sure that your script either only prints the exit status value, or that your expect call handles other possible outputs too.