I have an application, which uses IPC::Run in the following way:

IPC::Run::run([$cmd,@args],'>>',$outpath,'2>&1')
I have no information about $cmd - can be anything, and it is not on my control. Now my question:

Under the assumption that $cmd does not do unbuffered output, and doesn't fiddle around with buffering by itself (think of: just doing C style fwrite calls), is there a way I can control the buffer size (i.e. make it larger) of the pipe from the Perl side?

The code is currently executed on Windows and Linux. I understand that if there is at all a solution to my problem, it probably will look different on both platforms. This is OK. I'm not very optimistic, that a solution to this problem exist, but I don't know enough about the operating system internals.

Another idea which came to my mind, would be to replace the "IPC::Run::run" by an open(my $pipe,"$cmd ...|") and read from this pipe to my application, which then writes the output in larger chunks. This should work at least on Linux (possibly not Windows, because Windows does not, AFIK, support real pipes and needs to simulate them using files). However, if there were a solution of just increasing the buffer size for the output redirection, I would prefer that.

UPDATE:

I would like to sketch a possible solution - maybe someone can see whether or not it should work: I replace the call to IPC::Run::run by a call to IPC::Run::start and collect the output via a function:

my $harness=start(\@cmd,\'',\&f,\&f)
The function buffers the resulting lines, and if the number of characters exceeds a certain amount, it "flushes" the buffer by writing it to the output file. In order to bypass system-internal buffering, the output file is opened for writing using the :unix layer, and the data is written using syswrite instead of print. This is done in order to bypass stdio buffering. Of course this means that on Windows, I have to manually translate \n into 0x0d.0x0a manually.

Does this sound reasonable? Is there a simpler way to do it?
-- 
Ronald Fischer <ynnor@mm.st>

In reply to IPC::Run::run and buffering by rovf

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.