Various ways of accomplishing the effect that you are looking for:

  1. Use ">/tmp/command.out 2>/tmp/command.err" in the shell command string. Read the files after the command completes, and remove the files.
  2. Use IPC::Open3() and select() to monitor all pipes, reading data from pipes that have data ready.
  3. Spawn a thread off to read data from each sub process pipe. The thread would update a shared variable as data arrived on the pipe. The thread would exit when the pipe was closed.

In order to decide which method would work best, many factors need to be analyzed, including the acceptable level of complexity of the final product, the efficiency of the product, the purpose for capturing stdout/stderr, and the host environment (UNIX vs WIN32).


In reply to Re: fork and stdout/stderr by MarkM
in thread fork and stdout/stderr by smimp

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.