3 ms·
I sometimes want "nobuf" or something like it. I run some command that produces output promptly. Then I pipe it through grep or tee and the output doesn't show
by scottlamb 5y ago
I sometimes want "nobuf" or something like it. I run some command that produces output promptly. Then I pipe it through grep or tee and the output doesn't show up as promptly, because it's switched from line buffering to block buffering. "nobuf" fixes this.
There's a command called "stdbuf" on Linux systems that accomplishes the same thing in a different way. It sets some magic environment variables [1], and that tells the subprocess to use line buffering, assuming it's using glibc [edit: or any dynamically-linked libc] and stdio. No pty actually required then.
stdbuf's manpage has an example:
tail -f access.log | stdbuf -oL cut -d ' ' -f1 | uniq
This will immediately display unique entries from access.log
[1] edit: just checked. It injects its own code via the LD_PRELOAD environment variable, and then controls that with other environment variables. LD_PRELOAD is gross but it works, I guess.
- bandie91 5y agoLD_PRELOAD is the greatest thing ever.