Last time you asked this question in the CB, a long part of back and forth was spent on the difference between

print "echo $?"; # $ssh->exec("echo $?\n");

and

print 'echo $?'; # $ssh->exec('echo $?' . "\n")

You seem to have misunderstood the point that bart and I were trying to make. There are differences in Perl between strings in double quotes (") and strings in single quotes (''). To get a formal description of these differences, see perlop about "Quotes and Quotelike Operators".

Also during the last discussion, you claimed that this second approach did not work either. Maybe it does now for ou, but if it still does not, there was mention of things you could try next:

First approach - execute both commands in one ->exec statement:

$ssh->exec('your-program; echo $?');

Second approach - put all statements to execute in a shell script and execute that:

$ssh->exec('./shellscript-that-runs-your-program-and-then-outputs-doll +ar-question-mark.sh'); # where shellscript-that-runs-your-program-and-then-outputs-dollar-que +stion-mark.sh # contains the lines: # # #!/bin/sh # your-program # echo $?

In reply to Re: echo $? in perl by Corion
in thread echo $? in perl by bala_999

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.