Is there a buffer size attached to stdout?

后端 未结 3 1228
花落未央
花落未央 2020-12-16 18:14

I am trying to find some information on data limits related to stdout on Windows. I can\'t seem to find the information on MSDN.

  1. Is there a limit to how muc

3条回答
  •  盖世英雄少女心
    2020-12-16 18:37

    Some things to keep in mind:

    1) Jon is right - if the buffer limit is reached, the write call in your subprocess will block. You need to drain the stdout stream if it is not being redirected somewhere that will cause it to automatically drain - like a file. Pipes need to be drained, and usually, if you can "attach" to a subprocess' output, you're attaching to a pipe.

    2) The I/O to an output stream is probably buffered, which means that if the subprocess writes some information to stdout without explicitly calling flush(), which is almost always the case, you might not see the output. Flush is automatically called when the process exits, so if it's a short small subprocess you should be OK, but if it's not, you have no real way of forcing its output to show up when you want it to.

    3) Named pipes are essentially a buffer that the OS maintains that can be written to and read from - that is, they're like a file you can write to from one process and read from in another, without actually having the overhead of having a file on disk. Very handy for communication between processes, but all the I/O limitations with buffering / full buffers still apply.

提交回复
热议问题