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)
  • Re: Using subprocess module to launch a shell shell script that itself forks a process
    ... STDERR, the child will block waiting for the parent to read STDERR, ... process started by the shell script tries to read from STDIN. ... occurs because of the forked Java process, ...
    (comp.lang.python)
  • Re: Process.BeginErrorReadLine and BeginOutputReadLine; buffer not flushed?
    ... script, and redirects the stdout and stderr output from that script ... That means that if the process gets ahead of your reading process at all, the reading process can still wind up in a thread that's happy to keep reading the stream it's working on, while the OS buffers output sent to the other string. ...
    (microsoft.public.dotnet.languages.csharp)
  • 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)