Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: "tee"ing my own stdout/stderr

by conrad (Beadle)
on Jun 07, 2010 at 15:45 UTC ( [id://843516]=note: print w/replies, xml ) Need Help??


in reply to Re: "tee"ing my own stdout/stderr
in thread "tee"ing my own stdout/stderr

Thanks; I originally didn't look at that one 'cos of its low 0.05 version number. It has the same SIGINT problems I had as with the "|tee" solution (broken pipe errors rather than getting SIGINTs), but I've now worked out how to solve that: I was setting up the signal handler before starting the tees, but it occurred to me that maybe ignoring SIGINT before the tee and setting the handler up afterward would cause the children created by the tee to survive. This works. So, for example:

use POSIX; use File::Tee 'tee'; my $ctrl_c; my $outfile = "test.out"; my $errfile = "test.err"; $SIG{INT} = 'IGNORE'; tee(STDOUT, '>', $outfile) or die "Couldn't tee STDOUT to log file '$outfile': $!"; tee(STDERR, '>', $errfile) or die "Couldn't tee STDERR to log file '$errfile': $!"; $SIG{INT} = sub { $ctrl_c = 1; }; print "Testing 1.\n"; print STDERR "Test err 2.\n"; system("sleep 3 ; echo test 3; echo test 4 1>&2"); print "System: $?\n"; kill SIGINT, $$ if ($? & 127) == SIGINT; die "Interrupted!" if $ctrl_c; print "Done!\n";

Appears to do the job - cool, thanks!

Replies are listed 'Best First'.
Re^3: "tee"ing my own stdout/stderr
by salva (Canon) on Jun 08, 2010 at 08:25 UTC
    I have released a new version of File::Tee (0.06) that has the ignore-sigint behavior built in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://843516]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-04-16 06:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found