Skip to main content


also does anyone have a preferred solution to how sometimes when you pipe / redirect output, it gets buffered? https://blog.plover.com/Unix/stdio-buffering-2.html describes some potential options (like `stdbuf`), but I'm curious about what people actually reach for in practice

I always just end up suffering through it (“I guess I'll get the output if I wait long enough…”)

in reply to Julia Evans

Its a feature of the C library, which in generally you always want. If you are trying to view the output interactively, then maybe you are doing it wrong. You'd have to say more. "cat -u" in your pipe can sometimes help.
in reply to Michael Richardson

@mcr314 not sure what you mean by "doing it wrong", an example is that if I run this Python program as `python3 blah.py | grep .` it won't print out anything for a very long time

(obviously you can address it in this case by adding a flush in the python program, but it's not always possible to modify the program with that behaviour)

```
import time
import datetime

while True:
print(datetime.datetime.now())
time.sleep(1)
```

in reply to Julia Evans

@mcr314 `grep` have `--line-buffered` option.
In other cases `stdbuf` could help and yes, this can be a pain at times.
For #Perl scripts `$|++` or `$|=1` is a shorthand to turn off buffering on STDOUT.
Dunno for python.
This entry was edited (3 weeks ago)
in reply to Julia Evans

tcl-expect came with a tool called 'unbuffer' that redirected output through a pty pair, thus defeating stdio's isatty() buffering check
in reply to Julia Evans

`export PYTHONUNBUFFERED=1` covers python stuff, but I don't have anything truly general-purpose