Say I have two commands: foo and bar.
I want to execute both such that the output of foo is "redirected" to the input of bar. NOT only that though, I also want each byte written to foo's output stream to be directly/instantly written to bar's input stream.
If I use the command:
foo | bar
then the foo must terminate/exit before bar starts reading its input stream. I want bar to start reading its input stream in the same time the foo writes its output stream.
This answer here, if I understand correctly, states that there is a limit in the number of bytes buffered by the pipe and when they are filled then the pipe is "flushed" to the input stream of bar Maybe this limit can be reduced to '1' somehow?
You wrote:
foo
must terminate/exit beforebar
starts reading its input stream. I wantbar
to start reading its input stream in the same time thefoo
writes its output stream.
The assumption is not true. foo
is not required to terminate before it's output gets passed to bar
. True is that the glibc (assuming that both foo
and bar
are linked to it) performs output buffering. Unless the output of foo
goes to a terminal, the output gets written to a buffer and this buffer gets flushed when it reaches a certain size. If the output of foo
is so small that the buffer size won't get reached, then yes, the buffer will get flushed once foo
exits.
You can adjust the buffer size using the stdbuf
command. The following command won't buffer foo
's output:
stdbuf -o0 foo | bar
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With