Can't trap Pg warnings



Consider the following short script:

use strict;
use warnings;
use DBI;

my $h = DBI->connect( 'dbi:Pg:dbname=mytestdb', 'anonymous', '', );

# close( STDERR );
# open( STDERR, '>', \my $stderr );

warn 'before';
$h->prepare( 'CREATE TEMPORARY TABLE tmp ( i serial )' )->execute();
warn 'after';
$h->disconnect;

# print ">>\n$stderr<<\n";
__END__

The output I get from it looks like this:

before at test_script.pl line 10.
NOTICE: CREATE TABLE will create implicit sequence "tmp_i_seq" for serial
column " tmp.i"
after at test_script.pl line 12.

The output looks exactly the same if I pipe the command's standard output to
/dev/null ( i.e. what we're seeing was sent to standard error).

Now, if I uncomment the commented lines, the output looks like this:


before at script/test.pl line 10.
after at script/test.pl line 12.
<<

So, even though the messages given explicitly to warn in the script were
faithfully appended to the scalar $stderr, as intended, the notice from Pg
(about the implicitly created sequence) is gone: it shows up neither on the
screen, nor in the scalar $stderr.

How can I trap such notices?

Thanks!

tlm


P.S. It is tempting to blame the closing of STDERR for this problem, but
this a mandatory step. Without it, $stderr receives no output at all.


Relevant Pages

  • Re: using IPC::Open3 to write to *and* read from a process...
    ... script an external binary at all. ... output on STDOUT or STDERR, and if I can write to the process on STDIN ... sub handle_sigchild ... in any case a filehandle knows if it's open or not. ...
    (comp.lang.perl.misc)
  • Open3 with nonblocking reads
    ... I'm currently trying to execute a script within a script, ... single line should contain if it's STDOUT or STDERR, ... STDOuts were passed to the logfile. ...
    (comp.lang.perl.misc)
  • Re: Filter stdout and stderr Together
    ... I would like to write a script that filters lines from both stdout and ... script with the following syntax: ... stderr as expected, but with particular lines filtered out. ...
    (comp.unix.shell)
  • Re: A Grep and a couple Awks <and a lot of Tassilo help>
    ... > which you used to call your script. ... EOWARN is your Handle and << means to append into something called ... variable to stderr? ... > This needs less memory and gets rid of @selected altogether. ...
    (comp.lang.perl.misc)
  • Re: Redirecting STDERR
    ... the script, nor will it affect other programs running at the same time as the ... STDERR of the shell is different ... > Subject: Redirecting STDERR ...
    (perl.beginners)