Discussion:
tee: use unbuffered stdout
Ντέντος Σταύρος
2018-11-23 14:54:52 UTC
Permalink
Hello there,

I have tried to both store command output to a file and show it on the
terminal; hence I used `tee`.
However, I noticed that `tee` does heavy input buffering for my liking
(even on several `\n`).

What is worse is, the program I use does provide output without a
trailing `\n`, and, for the sake of this example,
"it is highly important" that I can see also partial output.

If I run the command unpiped to `tee`, then it works fine.

I searched online, however neither `stdbuf` nor `unbuffer` (from
`expect`) are able to help with the case.

Would it be easy enough to add a `--no-buffering` flag to `tee` instead?
Or, is there something else I missed from the internet for such operation?

Ντέντος Σταύρος
Pádraig Brady
2018-11-23 21:00:03 UTC
Permalink
Post by Ντέντος Σταύρος
Hello there,
I have tried to both store command output to a file and show it on the
terminal; hence I used `tee`.
However, I noticed that `tee` does heavy input buffering for my liking
(even on several `\n`).
What is worse is, the program I use does provide output without a
trailing `\n`, and, for the sake of this example,
"it is highly important" that I can see also partial output.
If I run the command unpiped to `tee`, then it works fine.
I searched online, however neither `stdbuf` nor `unbuffer` (from
`expect`) are able to help with the case.
Would it be easy enough to add a `--no-buffering` flag to `tee` instead?
Or, is there something else I missed from the internet for such operation?
Well tee is implicitly unbuffered.
I'm guessing the issue is with the default buffering mode
changing of the thing writing through the pipe.
I.E. if you replaced tee with cat you'd see the same thing.
Can you try using stdbuf on the filter before the tee, i.e.:

stdbuf -oL blah | tee blah

cheers,
Pádraig
Ντέντος Σταύρος
2018-11-24 08:08:28 UTC
Permalink
Post by Pádraig Brady
I'm guessing the issue is with the default buffering mode
changing of the thing writing through the pipe.
I.E. if you replaced tee with cat you'd see the same thing.
stdbuf -oL blah | tee blah
Hello Pádraig,

I had that already tried. And, any other combination of stdbuf.
However, since the call order was a script, calling a script, calling
an executable, it didn't really work at any level.

So, my solution was to force-sync calls on the "real" executable,
instead of any intermediate level.

Thank you, apologies for the uninformed call.

Loading...