Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!unido!mikros!mwtech!martin From: martin@mwtech.UUCP (Martin Weitzel) Newsgroups: comp.unix.questions Subject: Re: Pipes - child buffers its output Message-ID: <745@mwtech.UUCP> Date: 2 May 90 11:15:53 GMT References: <1364@ns-mx.uiowa.edu> Reply-To: martin@mwtech.UUCP (Martin Weitzel) Organization: MIKROS Systemware, Darmstadt/W-Germany Lines: 31 In article <1364@ns-mx.uiowa.edu> rpruess@umaxc.weeg.uiowa.edu (Rex Pruess) writes: :From a C program, I'd like to be to control an interactive program like :'ftp' or 'adb'. It should work as follows: : : write some commands to stdin of 'ftp' : read stdout of 'ftp' : interpret the results : write more commands (depending on the results) to stdin of `ftp' : : : :I've been successful in setting up the two pipes, but the child (e.g., :ftp) buffers all of its output until it exits. I need the child's output :returned on a line by line basis. What's the trick to accomplish this? I have bad news: There seems to be no such trick for the "pure mortal user" - the user without the source. To the benefit of thousands of lazy programmers who could or should not be obliged to use explicit "setbuf()" or "fflush()" the decission about buffering an I/O-stream is made automatically in the library routines. Unfortunately the one who had to decide about the "automatism" could not imagine such an advanced scheme as you describe above and hence decided that only I/O-streams connected to devices work unbuffered, while pipes and files are buffered. If your system uses shared libraries, and if you can exactly figure out some other things about the internal working of the library routines, you *might* have a small chance to overcome this. -- Martin Weitzel, email: martin@mwtech.UUCP, voice: 49-(0)6151-6 56 83