in reply to Copy contents of STDOUT
My best guess is that you are writing a wrapper script to intercept prints from other code. You can accomplish this by storing the STDOUT handle locally in the script and then redirecting the STDOUT handle to a variable. This is discussed in open. Something along the lines of:
#!/usr/bin/perl use strict; use warnings; open my $oldout, '>&', STDOUT or die "Can't dup STDOUT: $!"; my $stream; close STDOUT; open STDOUT, '>', \$stream or die "Can't open STDOUT: $!"; print "Hello!\n"; $stream .= "This line is new!\n"; print $oldout $stream;
where the above is assembled from code in open. Note that this should only be done at the highest level or undone in the same subroutine, as STDOUT is global and hence this could cause some weird action at a distance issues if you are incautious.
|
|---|