Good question. This is a little harder than necessary.
The problem is really in bar , in particular sys.stdin buffered. I tried opening sys.stdin with a smaller buffer size and using python -u , but that did not work. The manpage has the following:
-u Force stdin, stdout and stderr to be totally unbuffered. On systems where it matters, also put stdin, stdout and stderr in binary mode. Note that there is internal buffering in xreadβ lines(), readlines() and file-object iterators ("for line in sys.stdin") which is not influenced by this option. To work around this, you will want to use "sys.stdin.readline()" inside a "while 1:" loop.
In the end, this is what worked for me:
#!/usr/bin/python import sys import os while True: line = sys.stdin.readline() if not line: break sys.stdout.write(line) # or print, doesn't matter.
source share