in reply to Re: Confusion with finding strings in command output
in thread Confusion with finding strings in command output

It is a two-step process: first a shell command run under qx to retrieve the output (including STDERR thanks to the shell redirection), and then an analysis of the output.

Replies are listed 'Best First'.
Re^3: Confusion with finding strings in command output
by Anonymous Monk on Aug 30, 2014 at 20:07 UTC

    I know that standard error is being redirected. Do look again at OP's code (simplified)...

    my $SUCCESS = 0; my %Error = ( q[No such file or directory] => 1 ); my @out = qx { command here 2>&1 }; my $rc = $?; if ( $rc == $SUCCESS ) { # As I wrote earlier, if command was sucessful, then why would # there be no-file-found error (under normal conditions)? Else, # exit code cannot be trusted. ... = grep { $Error{$_} } @out; ... } ...
      Hmm, there is a misunderstanding. My point is that we have no idea about what output this line:
      my @out = qx { command here 2>&1 };
      produces, because we don't know what command here is. As an example, if "command here" if a shell find . -name ... -print ... command, it might very well produce successful lines as well as error lines.