On Wed, Jun 09, 2004 at 01:24:25PM +0100, Angus Leeming wrote: > I have put together some test code to read a child processes stdout, > stderr and to write data to the child's stdin. Moreover, I've managed to > do this using C++ streams.
Any reason we're not using one of the existing packages for this? > int nread = read(d_fd, d_buffer, d_bufsize); If you're using these interfaces you must have EINTR or set up SA_RESTART appropriately. > The question is, how do I know when to stop reading? To answer directly: fstat() works on pipes (but in a somewhat unusual fashion). To answer indirectly: always read in PIPE_BUF-sized buffers. Writes block after PIPE_BUF chars, so this will make sure we always get all the data. > there's none to be had. Ok, so I invoke > fcntl(d_fd[READ], F_SETFL, O_NONBLOCK); > so that read runs non-blocking. Still no good. An EAGAIN error breaks the > pipe. Actually, I'm surprised this breaks the pipe. > I think that I've reached the limits of my knowledge. Can anyone help me > out? Is it possible to re-open the pipe again? But, really, the actual fix is to warp in time back a few decades, and point out the designers of UNIX that level-triggered APIs are really the only sane way to go... regards john