- or download this
$alloutput=`cmd 2>&1`; # This should capture both stdout and stderr.
- or download this
% cat asdf
#!/bin/sh
echo "output to stdout"
echo "output to stderr" >&2
- or download this
% perl -e '$x=`./asdf 2>&1`;print "Captured $x"'
Captured output to stdout
output to stderr
- or download this
$output = `cmd 2>&1`; # either with backticks
$pid = open(PH, "cmd 2>&1 |"); # or with an open pipe
while (<PH>) { } # plus a read
- or download this
% perl -e 'open(F,"./asdf 2>&1|");while($x=<F>){print "Captured $x";}'
Captured output to stdout
Captured output to stderr