Is there a way to set up a Linux pipe to non-buffering or line-buffering?
Posted
by
ern0
on Stack Overflow
See other posts from Stack Overflow
or by ern0
Published on 2011-11-27T17:08:32Z
Indexed on
2011/11/27
17:50 UTC
Read the original article
Hit count: 190
My program is controlling an external application on Linux, passing in input commands via a pipe to the external applications stdin, and reading output result via a pipe from the external applications stdout.
The problem is that writes to pipes are buffered by block, and not by line, and therefore delays occur before my app receives data output by the external application. The external application cannot be altered to add explicit fflush() calls.
When I set the external application to /bin/cat -n (it echoes back the input, with line numbers added), it works correctly, it seems, cat flushes after each line. The only way to force the external application to flush, is sending exit command to it; as it receives the command, it flushes, and all the answers appears on the stdout, just before exiting.
I'm pretty sure, that Unix pipes are appropiate solution for that kind of interprocess communication (pseudo server-client), but maybe I'm wrong.
(I've just copied some text from a similar question: Force another program's standard output to be unbuffered using Python)
© Stack Overflow or respective owner