1833997 Members
4943 Online
110063 Solutions
New Discussion

Error redirect + Perl

 
network_4
Advisor

Error redirect + Perl

Hi,

I facing one issue, i want to redirect the output of one query to log file.
Let say

i am executing one database query in perl and by any reason query get failed so i want that what ever error message comes it will redirect to one file.

for example:

$bth->execute(); if this failed its throwing error on screen but i want to redirect error in one file so that latter i came to know what happened.
3 REPLIES 3
Oviwan
Honored Contributor

Re: Error redirect + Perl

Hey

CHeck this page:
http://www.perl.com/pub/a/1999/10/DBI.html

$sth->execute($lastname) # Execute the query
or die "Couldn't execute statement: " . $sth->errstr;

Regards
network_4
Advisor

Re: Error redirect + Perl

but still it will throw some error lines on screen and that i dont want as while script is running it should not come
Hein van den Heuvel
Honored Contributor

Re: Error redirect + Perl

Nothign much to do with perl.
You just have to manage STDERR.

For example with normal command line redirection:



$ perl -le 'print "Hello"; print STDERR "Boom"; print "World"'
Hello
Boom
World
$ perl -le 'print "Hello"; print STDERR "Boom"; print "World"' 2> error.log
Hello
World


Or from within the program

$ perl -le 'open STDERR,">error.log"; print "Hello"; print STDERR "Boom"; print "World"; die "Done"'
Hello
World
$ cat error.log
Boom
Done at -e line 1.


hth,
Hein.