Posts

Showing posts from June, 2008

Buffering in pipes

I'm trying to force a program not to buffer its output to stdout. Any program, all programs. It can't involve changing the source code or depending on weird or unportable stuff. It should be possible. It seems like I'm missing something obvious, but I can't figure out what. Some background info I've written a program ( ind ) that puts itself between a subprocess that it creates and the terminal. It acts as a filter for the output from the subprocess. Like this example, where it prepends "stdout: " to all lines that the subprocess prints to standard output: $ echo hej hej $ ./ind -p 'stdout: ' echo hej stdout: hej The dataflow is, from left to right: echo (the subprocess) -> pipe(2) -> ind -> the terminal (stderr runs through a separate pipe(2). Stdin has not been played with yet) So far so good. The problem is that the subprocess' libc (not the kernel) buffers all output using s...