Help for this page

Select Code to Download


  1. or download this
    $alloutput=`cmd 2>&1`; # This should capture both stdout and stderr.
    
  2. or download this
    % cat asdf
    #!/bin/sh
    echo "output to stdout"
    echo "output to stderr" >&2
    
  3. or download this
    % perl -e '$x=`./asdf 2>&1`;print "Captured $x"'
    Captured output to stdout
    output to stderr
    
  4. 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
    
  5. or download this
    % perl -e 'open(F,"./asdf 2>&1|");while($x=<F>){print "Captured $x";}'
    Captured output to stdout
    Captured output to stderr