in reply to Question: Redirection of stdout to scalar variable

IPC::Run provides an easy solution.
use strict; use warnings; use IPC::Run qw( run ); my @cmd = qw( sqlplus.exe -s scott/tiger@butthead ); my $in = <<'__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__ run \@cmd, \$in, \my $out; print $out;

Replies are listed 'Best First'.
Re^2: Question: Redirection of stdout to scalar variable
by jujiro_eb (Sexton) on Mar 20, 2009 at 23:01 UTC
    Thank you Ikegami!

    Since I am using Active Perl (Win32), IPC::Run did not show up in my package manager. I managed to use IPC::Run3 for the same. Thanks so much for the help. By the way the reason for all this is that dbms_output.put_line adds an extra LF at the end. I needed to strip it out. So the final code looks like this:

    use strict; use warnings; use IPC::Run3; my @cmd = qw( sqlplus.exe -s scott/tiger@butthead ); my $in = <<'__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__ run3 \@cmd, \$in, \my $out; print $out;
    Thanks again everybody!

    Ash

      IPC::Run did not show up in my package manager

      ppm install http://www.bribes.org/perl/ppm/IPC-Run.ppd

      Cheers,
      Rob