Back

tee and python

Keywords: tee, python, problem, not working, Linux

I just notices, that python and tee are not playing along so well. If you pipe your python program to tee, it appears that nothing is written to that file or the standart output

$ python my_script.py | tee output.txt

… And then …………… nothing happens

More veteran Linux/python people will go like “ahh, yeah sure, that’s the buffering” and they are totally right. To circumvent this issue, use unbuffered streams with python -u ... like in

$ python -u my_script.py | tee output.txt

This is my_script.py and I write justa little bit

This asks python to be totally unbuffered. From the man page:

-u     Force the stdout and stderr streams to be unbuffered.  This
       option has no effect on the stdin stream.