Chan Kim Chan Kim - 5 months ago 13
Python Question

a python print statement not shown when run through pipeline and tee command

I'm using simple function w1(str) to sometimes make the program stop and wait for a key. The code below works.

file :

#!/bin/env python

def w1(str):
print (str)
wait = raw_input()

if __name__ == '__main__':
w1('press a key')

How it runs (ok) :

press a key


But when I run | tee log
, it doesn't show anything and if I press a key it finishes not printing the message and waiting for the key. Actually, teh problem is the
is not displayed on the screen when run through tee command and it was waiting for my key. How can I make this
shown even when I run it with

EDIT : ok I learned that
python -u
does the trick. But originally my python script has
#!/bin/env python
at the beginning of the script so I run it | tee log
. I searched the net and found I can do :

ckim@stph45:~/test] setenv PYTHONUNBUFFERD 1
ckim@stph45:~/test] $ | tee log


Use -u to unbuffer,

python -u | tee log