carp() / STDERR

R

R McGlue

Hi
Im runnin a script which detatches from the tty and uses carp in
certain places. Is there any way i can redirect the STDERR messages to a
logfile instead of losing them to the ether??

many thanks

Ronan
 
P

Paul Lalli

R McGlue said:
Hi
Im runnin a script which detatches from the tty and uses carp in
certain places. Is there any way i can redirect the STDERR messages to a
logfile instead of losing them to the ether??

my $logfile = '/home/errs.txt';
open STDERR, '>>', $logfile or die "Could not redirect STDERR: $!";

(Note: Perl is smart enough to not lose track of the original STDERR if
the open fails here, so the die message will still be printed to
wherever STDERR is pointing if $logfile cannot be opened for appending.)

Hope this helps,
Paul Lalli
 
R

R McGlue

Paul said:
my $logfile = '/home/errs.txt';
open STDERR, '>>', $logfile or die "Could not redirect STDERR: $!";

(Note: Perl is smart enough to not lose track of the original STDERR if
the open fails here, so the die message will still be printed to
wherever STDERR is pointing if $logfile cannot be opened for appending.)

Hope this helps,
Paul Lalli
so if carp was to return and error message it would get written to
/home/errs.txt
?
 
P

Paul Lalli

R McGlue said:
so if carp was to return and error message it would get written to
/home/errs.txt
?

Any message printed to STDERR, including those printed by carp(), would
be printed to whatever file you named in $logfile (/home/errs.txt in
this case), yes.

Paul Lalli
 
R

R McGlue

Paul said:
Any message printed to STDERR, including those printed by carp(), would
be printed to whatever file you named in $logfile (/home/errs.txt in
this case), yes.

Paul Lalli
Right I'll elaborate a little more... I need to close STDERR if possible
as the script spawns multiple clients and servers which communicate with
each other via FIFO pipes. Its a fudged bit of code... but it works. I
need to close STDERR to minimise disk leakage. Aside from opening STDERR
and closing it around a carp or die command is there anyother way this
can be implemted more..... 'cleanly'

Ronan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,159
Messages
2,570,884
Members
47,419
Latest member
ArturoBres

Latest Threads

Top