One possible way to capture both command output and shell return code is to call the shell a second time. Example of success:
$ perl -E ' @c = `ls f*.*`; $return_code = `echo $?`; say scalar $ret +urn_code;' 0
Example of failure:
$ perl -E ' @c = `ls foobar.*`; $return_code = `echo $?`; say scalar +$return_code;' ls: impossible to find foobar.*: No such file or directory 512
Or something somewhat more similar to what you have:
$ ls *.* | sort | perl -E '@c = <>; say scalar @c, " files"; $return_ +code = `echo $?`; say scalar $return_code;' 294 files 0

Update @ 21:57 UTC: This last syntax does not seem to work properly. It seems that piping the result to the Perl process leads to the loss of the $? value of the initial process (well, or maybe it is more accurate to say that the child process forked by the pipe does not know about the status of the initial process). I get a 0 return code even when the initial command fails:

$ ls foobar.* | perl -E ' $return_code = `echo $?`; say scalar $retu +rn_code;' ls: impossible to find foobar.*: No such file or directory 0
Sorry if this last part of my answer turned out not to be very useful. The first part of my answer still gives you a possible way to go: you can call ./somebinary with back quotes from your Perl script and recover both the output and the return code.

In reply to Re: Capturing the stdout and exit code from a program piped to perl by Laurent_R
in thread Capturing the stdout and exit code from a program piped to perl by pattyj

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.