Pipes - child buffers its output

Martin Weitzel martin at mwtech.UUCP
Wed May 2 21:15:53 AEST 1990


In article <1364 at ns-mx.uiowa.edu> rpruess at 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 at mwtech.UUCP, voice: 49-(0)6151-6 56 83



More information about the Comp.unix.questions mailing list