CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
"Tee"ing output


New User

Oct 13, 2005, 4:30 PM

Post #1 of 1 (3751 views)
"Tee"ing output Can't Post

Hi all, this is my first post here in what looks like an excellent forum.

What I'm trying to do is log all output to STDOUT and STDERR to a file, which is easy, however I would also like it to display output on the console in real time.

This is what I'm trying:
#Pipe output to STDOUT and logfile
tie *STDOUT, 'Tie::Tee', "$logFile", ">&1";
open(STDERR, ">&STDOUT")

Using this, which I found in a book:
package Tie::Tee;
my $class = shift;
my @handles;
for my $path (@_) {
open(my $fh, ">$path") || die "can't write $path";
push @handles, $fh;
bless \@handles, $class;

sub PRINT {
my $href = shift;
my $handle;
my $success = 0;

foreach $handle (@$href) {
$success += print $handle @_;

return $success == @$href;

The problem with this approach is that when I do things like use open3 to open up an ssh session and pipe all output to STDOUT, the call to open3 croaks because the Tie::Tee class doesn't implement all of the methods it could...

Rather than figure out how to (probably inadequately)implement a dozen methods does anyone know of a more robust way of doing this? I've been using perl for a few months, so I don't mind seeing some deep magic if you have it, although it might take me a few minutes to figure out :)

Thanks in advance!


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives