Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: backticks fail to capture stderr even with explicit redirection

by hossman (Prior)
on Jul 04, 2011 at 18:19 UTC ( [id://912682]=note: print w/replies, xml ) Need Help??


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

A string which is (possibly) interpolated and then executed as a system command with /bin/sh or its equivalent. Shell wildcards, pipes, and redirections will be honored. The collected standard output of the command is returned; standard error is unaffected.

Given the bold statement, I call "bad design" on the last phrase. This has been very frustrating. Perl's philosophy of sometimes guessing what I mean rather than taking what I say at face value has now officially really ticked me off. At the very least, this construct should produce a warning message!

The documentation is correct. The backticks execute /bin/sh and capture the STDOUT of /bin/sh. the string you specify, including the redirection, is processed by /bin/sh -- perl (and hte backticks) don't know or care that you have asked /bin/sh to execut "cmd" and redirect cmd's STDERR to cmd's STDOUT (which then becomes the STDOUT of /bin/sh). All perl does is is take /bin/sh's STDOUT and give that to you.

See the previous comments explaining why it doesn't seem like it's working because of your flawed test case

The example you said does work would also appear to fail, if you had written it to work the same way (ie: print in single scalar variable in which you have slurped all of the data from F)

  • Comment on Re: backticks fail to capture stderr even with explicit redirection

Replies are listed 'Best First'.
Re^2: backticks fail to capture stderr even with explicit redirection
by Anonymous Monk on Jul 04, 2011 at 19:27 UTC
    The backticks (and system, open, etc ...) consult $Config::Config{sh} for which shell to use
    $ perl -V:sh sh='cmd /x /c';
Re^2: backticks fail to capture stderr even with explicit redirection
by keithhanlan (Initiate) on Jul 06, 2011 at 19:33 UTC
    The example you said does work would also appear to fail, if you had written it to work the same way (ie: print in single scalar variable in which you have slurped all of the data from F)

    Doh! good catch. Thanks for pointing that out.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2024-04-18 16:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found