http://www.perlmonks.org?node_id=956108

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

Hi, I am trying to remotely run an executable on a remote machine using the expect.pm module. I am able to successfully connect and execute the executable on remote machine.

Able to successfully get the executable output but facing issue when trying to check the return value of executable run

I am trying in following manner

 $exp->send("$command ; echo COMMAND_RET:$? | sed 's/^/COMMAND_OUT: /g'; echo -n END_; echo EXPECT\n");

Following format output gets displayed on console

<Command output>

COMMAND_OUT: COMMAND_RET: 0

END_EXPECT

My problem is that $? value printed in above code always displays 0, while the executable is returning non zero value too for some cases

While trying to manually execute the same command on shell prompt, correct value of $? gets appended COMMAND_OUT: COMMAND_RET: string.

Not able to detect why is S? value with expect->send is showing 0 value always.

Any advice on the same is really grateful