Greetings, honorable monks...
I come today to seek your wisdom...

I wrote a package from which a sub named '_runReadWrite' can be called to run processes on the server. After searching for the best solution, I finally chose to implement it using IPC::Open3, in a basic way that was taken from the Camel book:

# declare needed variables and connect to process local (*CHILD_IN, *CHILD_OUT, *CHILD_ERR); my ($childpid, @outlines, @errlines); $childpid = open3(*CHILD_IN, *CHILD_OUT, *CHILD_ERR, $cmd); # feed input to process, then close input print CHILD_IN $input; close (CHILD_IN); # save output and errors, close channels and process chomp(@outlines = <CHILD_OUT>); close (CHILD_OUT); chomp(@errlines = <CHILD_ERR>); close (CHILD_ERR); waitpid($childpid, 0); # return the result of the call return { OUTPUT => \@outlines , ERRORS => \@errlines };
Until today, any call to this sub worked perfectly. But unfortunately, things have changed...

The problem is that I now have a script that has, at some point, to close STDOUT, in order to unhook a child fork from the browser in a CGI script.

Now, later in that process, I make a call to my '_runReadWrite' function, which lamentably fails capturing the launched process' output.

What I would like to do, in the sub that runs open3, is to add some branching and/or additional tests so it still works when STDOUT is closed in the calling process. In other words, I would like it to continue working as it did so far when STDOUT is open, but use another way when that channel is closed. I have tried many things, searched for answers everywhere, but I did not manage to find a complete solution so far, and this is why I today address your wisdom...

Can anyone help me (and maybe others) with this ?
A proud initiate :)

In reply to IPC::Open3 & closed STDOUT by lgauthie

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.