Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: backticks fail to capture stderr even with explicit redirection

by ikegami (Patriarch)
on Jul 04, 2011 at 19:52 UTC ( [id://912691]=note: print w/replies, xml ) Need Help??


in reply to backticks fail to capture stderr even with explicit redirection

Your conclusions are wrong. STDERR is being captured and stored in $x.

$ cat asdf #!/bin/sh echo "line 1" echo "line 2" echo "line 3" >&2 echo "line 4" >&2 $ perl -le'$x=`./asdf 2>&1`; print "<<Captured $x>>"' <<Captured line 1 line 2 line 3 line 4 >>

Using backticks in list context will split the lines if that's what you want.

$ perl -e'print "Captured $_" for `./asdf 2>&1`;' Captured line 1 Captured line 2 Captured line 3 Captured line 4

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (6)
As of 2024-04-23 13:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found