in reply to open pipe without close

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.

Replies are listed 'Best First'.
Re^2: open pipe without close
by fast (Novice) on Feb 26, 2010 at 23:34 UTC

    Thank you very much for reply cdarke,
    The program on the other end is run in window and it connect to the unix server then return the data base on the parameter pass to it. I think this program is reading from the pipe from unix.
    The child process will end when the program done returning data.
    I take out the close command and i don't see any problem, but i just don't know what is the affect if I did that.

      Anonymous pipes (the type that you generate using | ) can only run between related processes on the same machine, and this applies to Windows and UNIX. So there must be some other software involved for the network communication.