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


In reply to Incorrect value 0 reported in command execution return value variable $?, when trying with expect->send command by Davewhite

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.