how do I prevent the close() from blocking until the child exits?
You could delay the close until you know for sure the child process has finished. Use the non blocking version of waitpid for this. From the docs:
use POSIX ":sys_wait_h"; $kid = waitpid(-1, WNOHANG);
This will see if any child has died (without blocking) and return the PID of said child (and the return value in $?, as normal). You can also wait for a specific child by using the pid of that child as first argument to waitpid.

Using this, you can make sure you only close the filehandle when the child has already exited. Just periodically check whether the child is dead, and close its filehandle if it is (you'll get a -1 return from the close, but that should be no problem).

Unfortunately, this is not portable to all OS. See waitpid for more information.

Update: 'now' ne 'know'

CU
Robartes-


In reply to Re: Re: open(KID, "-|") and wait()? by robartes
in thread open(KID, "-|") and wait()? by edan

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.