I've got a set of perl objects that need to capture the output of other objects. I accomplish this basically by saving STDOUT and then opening STDOUT on the write-end of a FIFO:
pipe READ_FIFO, WRITE_FIFO; open STDOUT_SAVED, ">&STDOUT"; open STDOUT, ">&WRITE_FIFO"; component->display(); #displays the component to STDOUT->WRITE_FIFO open STDOUT, ">&STDOUT_SAVED"; close WRITE_FIFO; $content=""; while (<READ_FIFO>) { $content .= $_; } close READ_FIFO; return $content;

The problem is that there appears to be a 4k (4096B) buffer limit. This solution works great with small components (text less than 4k), but for longer ones, the code hangs on the "component->display()". It basically fills up the buffer and waits for it to be cleared. But since I'm doing this all in one process, it never gets cleared :-)

Is there a way to increase the buffer size?

BTW, I'm not married to this approach, but it seemed the cheapest. I thought storing up a buffer of text in a FIFO was cheaper than forking a process. I also don't want to use a file--try to avoid the overhead and headaches involved with temporary files (especially accross multiple platforms).

Suggestions on other ways to catch the STDOUT to a variable are also welcome! TIA


In reply to FIFO buffer size limits by kostya

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.