#!/usr/bin/perl
use strict;
use warnings;
# run external commands
# redirect stdout and stderr
sub run_cmd{
my $cmd = shift;
my $pid = open(PH, "$cmd 2>&1 |");
while (
) {print $_; }
}
open(FH, ">", "perl-test.log");
*old_stdout = *STDOUT;
*old_stderr = *STDERR;
*STDOUT = *FH;
*STDERR = *FH;
my $ret = undef;
$ret = readpipe("cp a b ");
$ret = system("cp a b");
$ret = `cp a b`;
run_cmd("cp a b");
print "AA";
print STDERR "BB";
*STDOUT = *old_stdout;
*STDERR = *old_stderr;