in reply to Confusion with finding strings in command output

If there was a success in opening a file, when why would there be any string in error message about not finding a file (unless for perverse reason the command being called lies about the failure)?

You are searching for an exact string not for a partial match in grep.

Replies are listed 'Best First'.
Re^2: Confusion with finding strings in command output
by Laurent_R (Canon) on Aug 30, 2014 at 18:55 UTC
    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.

      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.