Please Help!

V

VJDIVINE

I need to catch an error printed by a module that I use. the problem
with this module is apart from using a log it also prints certain
errors directly to STDERR.
I want to catch these errors being printed to STDERR and log it into my
own logfile.

Since this module is an API I cannot change it's log config.

How to use eval and $SIG{__WARN__} to workaround this problem ? Or are
there any other solutions ?

Kindly guide me on this,
Thanks,
VJ
 
B

Ben Morrow

Quoth (e-mail address removed):
I need to catch an error printed by a module that I use. the problem
with this module is apart from using a log it also prints certain
errors directly to STDERR.
I want to catch these errors being printed to STDERR and log it into my
own logfile.

Since this module is an API I cannot change it's log config.

How to use eval and $SIG{__WARN__} to workaround this problem ?

If it is really printing directly to STDERR then you can't. If it uses
warn/die then you can use $SIG{__WARN__}/eval to catch the errors, but
you already knew that so I presume it isn't :).
Or are
there any other solutions ?

Open STDERR onto a string, like this:

my $STDERR_LOG;
open STDERR, '>', \$STDERR_LOG or die "can't catch STDERR: $!";

Note this requires 5.6(.1?) to work right.

Anything printed to STDERR will go into that string. You may want to dup
stderr somewhere else first, so's you can put it back afterwards.

Ben
 
V

VJ

HI Michele and Ben,

Thanks for your help.

I am still figuring out Michele's solution, as I am just an amateur to
perl.

I found this solution : Using IO::Capture::Stderr - check CPAN

This can capture stdin,stdout,stderr and so on. Hope this is of info to
u.

Thanks once again,
VJ
 

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

Similar Threads


Members online

Forum statistics

Threads
474,199
Messages
2,571,045
Members
47,643
Latest member
ashutoshjha_1101

Latest Threads

Top