Link to home
Create AccountLog in
Avatar of chp123
chp123

asked on

I am running a sybase stored proc from perl with lots of print statements, How do I retrieve these print statements into a logfile?

I am running a sybase stored proc from perl with lots of print statements, How do I retrieve these print statements into a logfile?  pl let me know the syntax
Avatar of rowansmith
rowansmith

Can you not just use the output redirector?  Are you executing this in a shell?

perlscript_command > filename.txt

Now all the print statements will be written to the file.

-Rowan
Avatar of chp123

ASKER

These are not the outputs from the perlscript, These are the debug statements used in the print statements of Sybase procedure. This Sybase procedure is called from a perlscript. We want to log the print statements from the Sybase into a logfile as this perl scrpt is fired as part of an eod job. This logfile can subsequently be used to trace the execution path.
Avatar of Joe Woodhouse
Sybase ASE's print statement is handled differently by each client tool. I'm not sure how Perl treats these. You will have a more repeatable result if you use SELECTs instead...
follow the steps in the FAQ to capture STDOUT or STDERR of an external program (your sysbase tool).

http://perldoc.perl.org/perlfaq8.html#How-can-I-capture-STDERR-from-an-external-command%3f


http://www.perl.com/doc/FAQs/FAQ/oldfaq-html/Q5.15.html

Kurt
That's a good point, I think print statements are usually considered part of STDERR.
Avatar of chp123

ASKER

Thanks for sharing the links. The solution proposed seems to be a generic one for reading any stderr/stdou. I was looking for something simpler that allows me to send "debug log" statements from a sysbase stored procedure to perl which eventually need to be writtent to some kind of trace/log file. I found below link that seems to address my need, but the entire solution is not clear, can some pls. share the details:
https://www.experts-exchange.com/questions/21373589/Printing-from-stored-procedure-to-perl.html

Thanks for you early response.
>I was looking for something simpler that allows me to send
>"debug log" statements from a sysbase stored procedure

O.K. now I'm a bit confused. Can you please tell us HOW do you run/call the stored procedure though perl? It will help to understand what you are doing and what you need.

>https://www.experts-exchange.com/questions/21373589/Printing-from-stored-procedure-to-perl.html

there is no solution and the question has been closed.

However, you can do this:

Connect to the Sybase DB with DBD::Sybase -> http://search.cpan.org/~mewp/DBD-Sybase-1.09/Sybase.pm

Then read about this "Retrieving OUTPUT parameters from stored procedures"

http://search.cpan.org/~mewp/DBD-Sybase-1.09/Sybase.pm#Retrieving_OUTPUT_parameters_from_stored_procedures

It's not about "catching" the output of print in the stored procedure, but about a way to get direct return data from the stored procedure. Maybe that's even better than any print statements. Can you tell us why you would need the print statements?

Kurt
Avatar of chp123

ASKER

I need to to create an application log file when the procedure is executing so as to monitor the  processing being done . Currently I use "print xxx" commands in my sybase procedure that come on the console when I run as standalone through AquaData Studio.  When the same procedure is run through PERL I need the output to come to a log file,  I run the procedure through perl using following code:
my $sql = qq{ exec TestProc  };
....
my $dbRows = $dbh->sql($sql);
..
If you put your diagnostic statements in SELECTs, they will be in STDOUT and Perl can easily capture them.

Mind you it seems it's about the same amount of work to capture STDOUT as it is STDERR...
again, can you please tell us HOW do you run/call the stored procedure though perl? What DB interface do you use? It depends on that interface if it is possible to capture STDOUT of a stored procedure!

Kurt
ASKER CERTIFIED SOLUTION
Avatar of kukno
kukno
Flag of Germany image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.