I think it depends on at what exact point the shell is doing the 2>&1 redirection.

I can't reproduce the problem with the command you've shown, i.e. here I do get

$ ./826946.pl CMD : >>echddo 'arghh'<< RETURN_CODE: >>32512<< CMD_RESULT : >>sh: echddo: not found <<

but when I remove one single quote ($cmd = "echddo arghh'"), so the shell command has a syntax error, I get like you

$ ./826946.pl sh: Syntax error: Unterminated quoted string CMD : >>echddo arghh'<< RETURN_CODE: >>512<< CMD_RESULT : >><<

The corresponding straces reveal that the redirection simply isn't being done in the latter case (note the missing dup2(1,2) ), presumably because my shell does the syntax checking before the 2>&1 redirection (which makes sense...), while in the other case, it does the redirection before starting to look for an executable 'echddo':

( cmd: echddo 'arghh' 2>&1 ) ... [pid 15950] rt_sigaction(SIGTERM, NULL, {SIG_DFL}, 8) = 0 [pid 15950] rt_sigaction(SIGTERM, {SIG_DFL}, NULL, 8) = 0 [pid 15950] fcntl(2, F_DUPFD, 10) = 10 [pid 15950] close(2) = 0 [pid 15950] fcntl(10, F_SETFD, FD_CLOEXEC) = 0 [pid 15950] dup2(1, 2) = 2 [pid 15950] stat("/home/almut/bin/echddo", 0x7fffb62454b0) = -1 ENOENT + (No such file or directory) [pid 15950] stat("/usr/local/sbin/echddo", 0x7fffb62454b0) = -1 ENOENT + (No such file or directory) [pid 15950] stat("/usr/local/bin/echddo", 0x7fffb62454b0) = -1 ENOENT +(No such file or directory) [pid 15950] stat("/usr/sbin/echddo", 0x7fffb62454b0) = -1 ENOENT (No s +uch file or directory) [pid 15950] stat("/usr/bin/echddo", 0x7fffb62454b0) = -1 ENOENT (No su +ch file or directory) [pid 15950] stat("/sbin/echddo", 0x7fffb62454b0) = -1 ENOENT (No such +file or directory) [pid 15950] stat("/bin/echddo", 0x7fffb62454b0) = -1 ENOENT (No such f +ile or directory) [pid 15950] write(2, "sh: ", 4) = 4 [pid 15950] write(2, "echddo: not found", 17) = 17 [pid 15950] write(2, "\n", 1) = 1 ... ( cmd: echddo arghh' 2>&1 ) ... [pid 15945] rt_sigaction(SIGTERM, NULL, {SIG_DFL}, 8) = 0 [pid 15945] rt_sigaction(SIGTERM, {SIG_DFL}, NULL, 8) = 0 [pid 15945] write(2, "sh: ", 4sh: ) = 4 [pid 15945] write(2, "Syntax error: Unterminated quote"..., 40Syntax e +rror: Unterminated quoted string) = 40 [pid 15945] write(2, "\n", 1 ...

What shell are you using?  (bash v3.2.39 here)

Your version seems to be trying to find the binary for 'echddo' before having set up the redirection...


In reply to Re: Unable to grab STDERR from a backtick command by almut
in thread Unable to grab STDERR from a backtick command by reasonablekeith

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.