printf STDERR "before: fileno(STDOUT)=%d\n", fileno(STDOUT);
open $old_stdout, ">&STDOUT" or die "open: $!";
close( STDOUT );
pipe( $smash_stdout, STDOUT );
printf STDERR "after: fileno(STDOUT)=%d\n", fileno(STDOUT);
####
before: fileno(STDOUT)=1
after: fileno(STDOUT)=6
##
##
printf STDERR "before: fileno(STDOUT)=%d\n", fileno(STDOUT);
open $old_stdout, ">&STDOUT" or die "open: $!";
# _don't_ explicitly close STDOUT here
local(*RH, *WH);
pipe RH, WH;
open STDOUT, ">&WH" or die "open: $!";
printf STDERR "after: fileno(STDOUT)=%d\n", fileno(STDOUT);
##
##
before: fileno(STDOUT)=1
after: fileno(STDOUT)=1
##
##
open $old_stdout, ">&STDOUT" or die "open: $!";
local(*RH, *WH);
pipe RH, WH;
open STDOUT, ">&WH" or die "open: $!";
# write something to the pipe
print "foo";
# and have some fork/exec'ed process write to the pipe (via stdout)
system('echo bar');
close WH;
my $out = ;
print STDERR "got from pipe: $out"; # $out is "foobar\n"