It is down to buffering, what the program at the other end expects and does, and even which operating system.
When a program is writing to a pipe (as in your example) it will block until the pipe is read, however at the low level there is a pipe buffer that data is written to. It could be that there is data in that buffer that you might miss. The program might also have some tidying up to do. At what point does your child process end? If you close the pipe handle then it will recieve a SIGPIPE (broken pipe) signal on UNIX/Linux, and can handle that. On Windows the WriteFile API returns an error of ERROR_BROKEN_PIPE, which again can be handled by the application.
If the program is reading from the pipe then things are a little simpler, when you close the handle the program gets end-of-file, and can close normally.
Not specifically closing the pipe defers all this until the end of your program, when perl closes all open file handles for you - a bit like expecting your mother/partner to tidy up after you.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.