John Levon wrote: > 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?
Well, I've googled and googled and failed to find anything that can --- in a platform independent way --- spawn a child process and communicate with it through the child's stdin, stdout, stderr. So I thought I'd try and understand the issues, on unix at least. I took the code that's in ispell.C and hacked it into a stand-alone app. I then tried to clean it up, but got a bit stuck trying to separate out 'child_process_with_pipes' from 'ispell_communicator'. However, I then happened across the stuff in Ch19 of C++ Annotations which is much, much cleaner than the stuff we have, so I got to playing. I'll post it when it's finished. > 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. You're a wizard. >> 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. <shrug>it happens<\shrug> -- Angus