Re: print sybase system stored procedure output to filehandle





On Oct 13, 3:39 am, peter.br...@xxxxxxxxxxxxxx wrote:
Hi - is there a simple way to redirect the output from a Sybase system
stored proc [sp_recompile] to an open filhandle - currently the output
- 'Each stored procedure and trigger that uses table 'xxxxx will be
recompiled the next time it is executed.' - is printed on the console.

As I understand the DBI API there's no concept of the database
operations having a STDOUT or a STDERR, the only things that database
operations can return are a single rowset or an exception (error
string).

However there are tricks you can use in Perl to capture STDERR and/or
STDOUT from subprocesses and black-box Perl subroutines. Exactly which
would work here would depend on the implementation of DBD::Sybase.

I don't use DBD::Sybase but I'm going to guess that the string you are
seeing is being output to the current filedescriptor 2 directly by the
sybase client library.

If this is the case you can capture in using something like

#!perl
use strict;
use warnings;
use AtExit;
use IO::Handle;
open my $log, '>', 'log.log' or die $!;

{
open my $save_STDERR, '>&', *STDERR;
my $restore_STDERR = AtExit->new( sub {
open STDERR, '>&', $save_STDERR;
});
$log->flush; # Subprocess unbuffered so avoid dissordered o/p
open STDERR, '>&', $log;
system 'xxx'; # Subprocess that will error
# $restore_STDERR goes out-of-scope and puts back the original
STDERR
}

__END__

Of course it could be that DBD::Sybase is writing the output in some
other way in which case this won't help. For example if it forked-off a
helper process as soon as you open the filehandle and then wrote to the
fd 2 of that process you've have a somewhat harder time getting hold of
the outout corresponding to a given DBI transaction.

.



Relevant Pages

  • Re: Core dump with "in memory" file
    ... close STDERR; ... This is perl, ... With 5.10.1 for i386-freebsd I can reproduce the bug without the ... Segmentation fault ...
    (comp.lang.perl.misc)
  • Re: eval running external script
    ... I own Perl in a Nutshell and the Perl black book, ... Illegal division by zero at run_task.pl line 5. ... place as the script's STDOUT and STDERR." ...
    (comp.lang.perl.misc)
  • Re: printing die error ina file
    ... Jeff Pang wrote: ... to STDERR) to the appropriate files, ... /dev/null so it doesn't clutter up either the console or the log files ... The point I was trying to make is that Perl has its own error mechanisms that don't use die and can't be trapped with $SIG. ...
    (perl.beginners)
  • Re: Core dump with "in memory" file
    ... close STDERR; ... This is perl, ... With 5.10.1 for i386-freebsd I can reproduce the bug without the ... Segmentation fault ...
    (comp.lang.perl.misc)
  • Identify if a scalar is int, double or text
    ... The first is obviously an int, the second is text, the third a double ... print STDERR "Beginning of program\n"; ...
    (comp.lang.perl.misc)