under unix shell 2>&1 redirects STDERR to STDOUT. If you then add a pipe you do indeed get the whole lot going down the pipe (so if this pipe then connected to a perl file handle you would be reading STDERR and STDOUT mixed together in Perl). Perl sends it's warnings to STDERR as this little test shows

# A simple perl script to generate a warning : perl -we 'my $t; my $t' "my" variable $t masks earlier declaration in same scope at -e line 1. # the same with STDOUT redirected to null : perl -we 'my $t; my $t' >/dev/null "my" variable $t masks earlier declaration in same scope at -e line 1. # same with STDERR to null, aaah the sound of silence : perl -we 'my $t; my $t' 2>/dev/null :
What may be enough for you is to check the exit code of the script you call (hopefuly it exits with 0 when it runs OK and non-zero values for failures
my $cmd="ls /no/way"; my @data=`$cmd`; if($?) { print "$cmd failed with exit code $?\n"; exit 1 } foreach (@data) { chomp; my @ret=split; # do something with @ret here ? }

This is running the external script to completion first then checking it did not give an error code before going on to process the results.

Cheers,
R.


In reply to Re: Error trapping while capturing stdout by Random_Walk
in thread Error trapping while capturing stdout by ccarden

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.