Davewhite has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on Issue while retrieving the unix command return status when executed with perl CPAN module expect.pm
  • Download Code

Replies are listed 'Best First'.
Re: Issue while retrieving the unix command return status when executed with perl CPAN module expect.pm
by davido (Cardinal) on Feb 27, 2012 at 06:55 UTC

    Seems like this came up just a day ago...

    $? is being interpolated as a Perl variable and its value is what's making it to the shell. You probably just need to escape the sigil:

    $expect->send( "grep xyz *; echo RET_VALUE:\$?" );

    ...or if there's no need for interpolation anywhere else in your string literal, use single (non-interpolating) quotes:

    $expect->send( 'grep xyz *;echo RET_VALUE:$?' );

    Update: I just realized why it seemed so familiar: You already asked a question that got you a nearly identical answer, yesterday, in this thread: Incorrect value 0 reported in command execution return value variable $?, when trying with expect->send command. Why? ...At least you got answers that confirmed one another. Seek a third opinion and you'll really have covered your @$$ ;)


    Dave