Hello Monks,
A few days ago monk Kyle helped me out with redirecting stdin to Oracle's sql*plus program. It worked like a charm. Now I am stuck about capturing the stdout messages generated by sql*plus to a scalar variable. I used IO::String and it did not work. Then I tried the following code, which also failed to capture the stdout from sql*plus. Interestingly enough, I was able to capture simple print statement's output using both IO::String as well as the code below.
use strict;
use warnings;
my $TEMP1;
my $OLD_STDOUT_HANDLE;
my $NEW_STDOUT_HANDLE;
open NEW_STDOUT_HANDLE, ">&STDOUT";
close STDOUT;
open STDOUT, ">", \$TEMP1;
open my $pipe_fh, '|-', "sqlplus.exe -s scott/tiger\@butthead"
or die "Can't open pipe: $!";
print {$pipe_fh} <<"END_OF_SQL"
set echo off
set lines 1000
set trims on
set serverout on size 999999
set feed off
exec dbms_output.put_line('Hello There');
exit;
END_OF_SQL
;
close $pipe_fh;
close STDOUT;
open STDOUT, ">&NEW_STDOUT_HANDLE";
print "6.\n";
print $TEMP1;
I would once again greatly appreciate your help.
Regards.
Ash
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.