Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > carp() / STDERR

Reply
Thread Tools

carp() / STDERR

 
 
R McGlue
Guest
Posts: n/a
 
      08-31-2004
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
 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      08-31-2004
"R McGlue" <> wrote in message
news:ch1ksm$nje$...
> 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


 
Reply With Quote
 
 
 
 
R McGlue
Guest
Posts: n/a
 
      08-31-2004
Paul Lalli wrote:

> "R McGlue" <> wrote in message
> news:ch1ksm$nje$...
>
>>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
>
>

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

 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      08-31-2004
"R McGlue" <> wrote in message
news:ch21u2$omd$...
> Paul Lalli wrote:
>
> > 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.)
> >

> 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


 
Reply With Quote
 
R McGlue
Guest
Posts: n/a
 
      09-01-2004
Paul Lalli wrote:
> "R McGlue" <> wrote in message
> news:ch21u2$omd$...
>
>>Paul Lalli wrote:
>>
>>
>>>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.)
>
>>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
>
>

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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading stdout and stderr separately ladygrinningsoul Perl 3 04-25-2005 04:25 PM
Another newbie question re: STDERR and IPC::open3(), nowait() and zombies Dave Newberry Perl 0 10-17-2004 06:41 PM
redirecting stderr and stdout Jon Landenburer Perl 1 05-13-2004 07:38 AM
How to redirect stdout&stderr into files in Tomcat 4.1.29 on RedHat 9 ? Java 3 01-11-2004 10:30 PM
redirect stdout & stderr tomcat 4.1 VisionSet Java 6 09-20-2003 01:37 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57