Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^6: capturing stderr of echo piped to a file

by boftx (Deacon)
on Oct 29, 2014 at 23:21 UTC ( #1105564=note: print w/replies, xml ) Need Help??


in reply to Re^5: capturing stderr of echo piped to a file
in thread capturing stderr of echo piped to a file

Okay I stand corrected in that order matters. That said, I honestly can't remember ever seeing 2>&1 not coming at the end of the command line, probably because doing so seems to indicate that it won't be captured to STDOUT as one desires.

~/stuff > cat JGBtest.txt Just a starting point ~/stuff > perl foobar.pl 2>&1 >>JGBtest.txt Going to STDERR ~/stuff > cat JGBtest.txt Just a starting point Normal STDOUT ~/stuff > perl foobar.pl 2>&1 >>JGBtest.txt | grep STD Going to STDERR ~/stuff > perl foobar.pl 2>&1 | grep STD Going to STDERR Normal STDOUT ~/stuff >

With all of the foregoing comments by both you and me in mind, I think you're first comment implies that it must come first in order to be captured. But in the interest of being complete even if I'm wrong, I included the final tests that does actually demonstrate what is happening on the command line (though it is not intuitive.) Also, it is possible that setting $| = 1; might alter the output ordering.

You must always remember that the primary goal is to drain the swamp even when you are hip-deep in alligators.

Replies are listed 'Best First'.
Re^7: capturing stderr of echo piped to a file
by Crackers2 (Parson) on Oct 30, 2014 at 18:31 UTC
    Okay I stand corrected in that order matters. That said, I honestly can't remember ever seeing 2>&1 not coming at the end of the command line, probably because doing so seems to indicate that it won't be captured to STDOUT as one desires.

    You're entirely correct that wanting to redirect both STDOUT and STDERR is the most common case, and for that one you do indeed need the 2>&1 at the end.

    However that does not appear to be what the OP wants; Unless I misread the question, he wants to capture STDERR output using the backticks, while having STDOUT going to the file. For that you need the reverse otder.

    With all of the foregoing comments by both you and me in mind, I think you're first comment implies that it must come first in order to be captured.

    ... in order to be captured by the backticks instead of going to the file with STDOUT.

    Also, it is possible that setting $| = 1; might alter the output ordering.

    I think you're right about that.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1105564]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2021-12-03 20:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    R or B?



    Results (30 votes). Check out past polls.

    Notices?