I want to open a process and be able to read it's stdout, which I would normally do with putting a pipe at the end of my command and looping on the <> construct over the input handle.

Thing is, I would also like to be able to open it in NONBLOCKING and be able to go off and update status displays while waiting for input.

I'd love for it to be as simple as

while (<$fh> && ! eof($fh)){ unless ($_) { update_status; next; } #process input... }
But it doesn't look like things are that easy cuz the buffering lib doesn't know how to handle a non-blocking case.

So, I have to roll my own <> in a proc with read calls and such (been there, got programs that do that...I can copy my working code)...But ... I seem to remember on those progs, I handled the forking.

I was wondering if the open function's rules about doing a fork if it sees the "pipe char", still hold if I use the 3-arg form of open and specify O_NONBLOCK at open time, (then have to get the fileno from the FD, and use select or similar to do my waiting...)...

The key point being -- will open handle the fork and assignment of an IO-waiting process, or will the O_NONBLOCK interfere with that? I'm sorta guessing the latter, but was hoping someone might know for sure.....?

Thanks...


In reply to open (.."proc|",O_NONBLOCK)? by perl-diddler

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.