I am feeling silly, so try this:
# Takes a filehandle and filename and has output to that handle go # to STDERR and to that filename. It will work even if the handle # being tied is STDERR itself. No escaping is done for the filename, # caveat programmer sub tee_to_stderr { my $file = shift || die "No filename passed\n"; my $ip = open (STDERR, "| perl") || die "Cannot pipe to Perl: $!"; my $fh = select(STDERR); $| = 1; select($fh); print STDERR qq( unless(open (OUT, ">$file")) { print STDERR "Cannot write to $file: \$!\n"; kill 9, getppid(); } select(STDERR); \$| = 1; select(OUT); \$| = 1; while (<>) { print OUT; print STDERR; } ); print STDERR "\n__END__\n"; }
(The attempt to kill the parent won't work in Windows, otherwise this gives you one very convoluted way to do something that should be simple.)

The idea is to not just redirect STDERR, but also to have it still going to STDERR so that you get your log and they still see their own errors.

The right way to do this should use IO::Tee, but the problem is that one of the filehandles you want to tee is STDERR. This gets us into the same recursion that you saw in Filehandle Filter. I don't have the energy at the moment to offer a good solution, though I am sure there is one and that I will be very irritated with myself when I see it...

UPDATE
I am indeed irritated. Fastolfe pointed out that you can always dup a filehandle:

open(NEW, ">&OLD") or die "Cannot dup OLD: $!";
So dup STDERR, then proceed to do what you want.

In reply to Re (tilly) 1: How does one redirect STDERR to a file? ((Filehandle by tilly
in thread How does one redirect STDERR to a file? ((Filehandle, redirection, logging)) by princepawn

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.