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!


In reply to Re^2: "tee"ing my own stdout/stderr by conrad
in thread "tee"ing my own stdout/stderr by conrad

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.