Discussion:
how to redirect warnings to a file
lakshmi priya
2007-03-22 08:16:07 UTC
Permalink
Hi,
How do I redirect the warning messages from my perl script to a
different file? By default they are all getting printed on the terminal.
Andrew Curry
2007-03-22 10:55:08 UTC
Permalink
./script.pl 2> err in unix.

Or print STDERR "error message" in your program.

-----Original Message-----
From: lakshmi priya [mailto:***@gmail.com]
Sent: 22 March 2007 08:16
To: ***@perl.org
Subject: how to redirect warnings to a file

Hi,
How do I redirect the warning messages from my perl script to a
different file? By default they are all getting printed on the terminal.


This e-mail is from the PA Group. For more information, see
www.thepagroup.com.

This e-mail may contain confidential information. Only the addressee is
permitted to read, copy, distribute or otherwise use this email or any
attachments. If you have received it in error, please contact the sender
immediately. Any opinion expressed in this e-mail is personal to the sender
and may not reflect the opinion of the PA Group.

Any e-mail reply to this address may be subject to interception or
monitoring for operational reasons or for lawful business practices.
--
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
http://learn.perl.org/
lakshmi priya
2007-03-24 03:35:21 UTC
Permalink
Hi all,

Thank u for your help :)

Jeff Pang
2007-03-22 10:59:32 UTC
Permalink
Post by lakshmi priya
Hi,
How do I redirect the warning messages from my perl script to a
different file? By default they are all getting printed on the terminal.
Hello,

You can redirect all 'die' or 'warn' messages to files via re-defining the SIGDIE and SIGWARN handler.

Like:

$SIG{__DIE__} = \&log_die;
$SIG{__WARN__} = \&log_warn;

sub log_die
{
write_log(@_);
die @_;
}

sub log_warn
{
write_log(@_);
}

sub write_log
{
open LOG,">>",$logfile;
print LOG @_,"\n";
close LOG;
}
--
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
http://learn.perl.org/
Jeff Pang
2007-03-22 11:01:53 UTC
Permalink
Post by Andrew Curry
Or print STDERR "error message" in your program.
This is not good because warning info are most likely generated by Perl parser not your programs.
--
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
http://learn.perl.org/
Mumia W.
2007-03-22 12:52:58 UTC
Permalink
Post by lakshmi priya
Hi,
How do I redirect the warning messages from my perl script to a
different file? By default they are all getting printed on the terminal.
In addition to Jeff Pang's suggestion, read "perldoc -f open". You can
redirect STDERR to a file:

open STDERR, '>>', 'mylogfile.log'
or die('...');
--
To unsubscribe, e-mail: beginners-***@perl.org
For additional commands, e-mail: beginners-***@perl.org
http://learn.perl.org/
Loading...