As far as I can tell, the advised method of calling a shell command and reading its output is via popen
(e.g., this answer). However, the man page for popen(3)
says:
Note that output popen() streams are block buffered by default.
How do I make my read-only pipe non-buffered?
For example:
FILE* ro_pipe = popen("echo hello", "r");
won't fill out the 4KB output buffer, but I'd want to have the output data ready to read as soon as it is written to the stdout of the shell command.