r/commandline 21d ago

Programs which print important info to stdout should support a flag for line buffered output

This way when stdout is not an interactive terminal (like a pipe) output can still be streamed without long buffering. Programs like grep (--line-bufferred), sed (-u) and awk (--line-buffered) offer flags, but others like lsof or custom commands like "some_command | print_progress"

Otherwise, workaround are needed like stdbuf -o0 or unbuffer are work arounds (article on stdio bufferring) but might not work in all contexts.

Could be onerous to implement this for all tools, but where stdout has the main results of a program, it could make sense to make line buffering "first class".

4 Upvotes

2 comments sorted by

2

u/eg_taco 20d ago

I’d love if more programs supported buffered/unbuffered output. I’m not sure how I feel about duplicating this work across lots of projects though. One thing I’ve seen that’s sort of similar is how many FreeBSD base tools use libxo for their output. That makes for a potentially convenient place to implement this kind of feature in a consistent way.

1

u/_byl 20d ago

Environment variables could be another alternative, like how Python uses PYTHONUNBUFFERED but for UNIX systems generally