in some legacy code (running on Windows) we came across this to capture the output of an external command:
We are currently having some discussions on whether the above construct involves a shell (I think it does) and whether it is better then simply using backticks (I think it is not).sub fetch_cmd { my ($cmd) = @_; my $ret; unless ( open FH, $cmd . ' 2>&1 |' ) { return; } while (<FH>) { $ret .= $_; } close FH; return $ret; }
What is your opinion?
In reply to capturing command output by morgon
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |