Fixing capturing so that it works on Perl 5.6.1
git-svn-id: svn://10.0.0.236/trunk@156072 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
85d007f932
commit
d2e089fef6
@ -51,20 +51,29 @@ sub system_capture {
|
||||
# Back up the original STDOUT and STDERR so we can restore them later.
|
||||
open(OLDOUT, ">&STDOUT") or die "Can't back up STDOUT to OLDOUT: $!";
|
||||
open(OLDERR, ">&STDERR") or die "Can't back up STDERR to OLDERR: $!";
|
||||
use vars qw( $OLDOUT $OLDERR ); # suppress "used only once" warnings
|
||||
use vars qw( *OLDOUT *OLDERR ); # suppress "used only once" warnings
|
||||
|
||||
# Close and reopen STDOUT and STDERR to in-memory files, which are just
|
||||
# scalars that take output and append it to their value.
|
||||
# XXX Disabled in-memory files in favor of temp files until in-memory issues
|
||||
# can be worked out.
|
||||
#close STDOUT;
|
||||
#close STDERR;
|
||||
#open STDOUT, ">", \$output or die "Can't open STDOUT to output var: $!";
|
||||
#open STDERR, ">", \$errors or die "Can't open STDERR to errors var: $!";
|
||||
#close(STDOUT);
|
||||
#close(STDERR);
|
||||
#open(STDOUT, ">", \$output) or die "Can't open STDOUT to output var: $!";
|
||||
#open(STDERR, ">", \$errors) or die "Can't open STDERR to errors var: $!";
|
||||
my $outfile = tempfile();
|
||||
my $errfile = tempfile();
|
||||
open(STDOUT, ">&", $outfile) or die "Can't dupe STDOUT to output file: $!";
|
||||
open(STDERR, ">&", $errfile) or die "Can't dupe STDERR to errors file: $!";
|
||||
# Perl 5.6.1 filehandle duplication doesn't support the three-argument form
|
||||
# of open, so we can't just open(STDOUT, ">&", $outfile); instead we have to
|
||||
# create an alias OUTFILE and then do open(STDOUT, ">&OUTFILE").
|
||||
*OUTFILE = *$outfile;
|
||||
*ERRFILE = *$errfile;
|
||||
use vars qw( *OUTFILE *ERRFILE ); # suppress "used only once" warnings
|
||||
open(STDOUT, ">&OUTFILE") or open(STDOUT, ">&OLDOUT")
|
||||
and die "Can't dupe STDOUT to output file: $!";
|
||||
open(STDERR, ">&ERRFILE") or open(STDOUT, ">&OLDOUT")
|
||||
and open(STDERR, ">&OLDERR")
|
||||
and die "Can't dupe STDERR to errors file: $!";
|
||||
|
||||
# Run the command.
|
||||
$rv = system($command, @args);
|
||||
@ -78,13 +87,13 @@ sub system_capture {
|
||||
$output = <$outfile>;
|
||||
$errors = <$errfile>;
|
||||
}
|
||||
|
||||
|
||||
# Restore original STDOUT and STDERR.
|
||||
close(STDOUT);
|
||||
close(STDERR);
|
||||
open(STDOUT, ">&OLDOUT") or die "Can't restore STDOUT from OLDOUT: $!";
|
||||
open(STDERR, ">&OLDERR") or die "Can't restore STDERR from OLDERR: $!";
|
||||
|
||||
|
||||
return ($rv, $output, $errors);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user