Your skill will accomplish what the force of many cannot |
|
PerlMonks |
backticks fail to capture stderr even with explicit redirectionby keithhanlan (Initiate) |
on Jul 04, 2011 at 16:50 UTC ( [id://912672]=perlquestion: print w/replies, xml ) | Need Help?? |
keithhanlan has asked for the wisdom of the Perl Monks concerning the following question: As soon as I posted this question, found the following in man perlop: 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! ...Original post follows... Can somebody suggest why backticks aren't able to capture stderr in our environment? I generally use open() with pipes to capture the output of commands but a colleague was using back-ticks and encountered behaviour that runs counter to sample code I've seen all over the place, namely: However, it doesn't seem to work in our environment for some reason and I would like to understand why. Here's a simple test: Now, witness the following: Notice how the stderr output escapes the capture. This is contrary to examples that I've seen, for example, here: How can I capture STDERR from an external command? which explicitly states: Note that if I use the latter construct, it does work:
In our environment, this is reproducible on both Linux & Solaris using perl 5.5.3, 5.8.5, and 5.12.2. Any help or hints would be appreciated. Thank you,
Back to
Seekers of Perl Wisdom
|
|