Dear Monks
I have a problem with a module which uses IPC::Open2. Normally this module works but when I wrap it in the following code it doesn't:
my $module = MyModule->new() ; ... my $out = '' ; { local *STDOUT ; local *STDERR ; open (STDOUT,">>", \$out) ; open (STDERR,">>", \$out) ; $module->process() ; } ....
This will make sure that everything printed by $module is redirected to $out.
Here is what's going on in MyModule
use IPC::Open2 ; .... sub process { .. my $pid = open2( *Reader, *Writer, "some_prog" ); print Writer "$some_options" ; my @prog_out = <Reader> ; close Writer; close Reader; .. return @output ; }
Everything printed by some_prog is now redirected to $out and not to @prog_out. Any suggestions how to fix this ?

Cheers
LuCa

ps the main code is part of a cgi script, so I need to catch everything printed by $module, because it is not part of what the users want to see!

Update:sorry tye, you're right. You've said it to me before!! The problem was that there were other modules involved which did things like
print STDOUT "....." ;
I've fixed this and now I can do
open OUT,">>", \$out ; select OUT; $| = 1 ;
Thnx!!

In reply to Problem with IPC::Open2 when STDOUT/STDERR are redirected by jeanluca

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.