A simple question really: I want to capture the STDERR from
commands like croak and cluck into a log file that records all
output of my program. I've read the previous comments in Perl Monks
and I find the following in the Camel book:
use FileHandle;
use Carp qw (cluck croak);
my $LOG_FH = new FileHandle( "somefile", "w" );
my $fileno = fileno $LOG_FH;
open STDERR, ">&$fileno" or croak "Can't dup STDERR.";
cluck "Testing the output of Carp commands.";
(I need to use the $fileno because the ">&" dup operation doesn't
work on I/O typeglobs.)
This works fine: all STDERR after this goes into $LOG_FH, but
it no longer goes to the terminal.
But what I want is like the command "tee". I want STDERR to go to
the terminal window, AND to be duplicated into the $LOG_FH
filehandle.
Any clues??
Thanks,
-Cadphile
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.