0

This is very weird that "tee" is not working for the python scripts. I have a program called "test.py" and trying to output to the terminal and to a log file using shell commands. I have tried

$python test.py | tee -a result.txt
$python test.py | tee result.txt
$python test.py | >> result.txt
$ (python test.py) | tee -a result.txt

It just does not work. I do not want to change anything in my program cause there are more than 200 print statements.

Thanks in advance.

Ashwini Chaudhary
  • 244,495
  • 58
  • 464
  • 504
user2452845
  • 51
  • 1
  • 1
  • 5

1 Answers1

1

From @kqr below, run it in unbuffered mode:

python -u test.py | tee result.txt
U2EF1
  • 12,907
  • 3
  • 35
  • 37
  • Does the same thing.. It takes around 30-40 seconds to display on the terminal by dumping 100s of statement at once. – user2452845 Jun 06 '13 at 17:04
  • @user2452845 It sounds like your program is waiting for a while and then flushing the output. You can try peppering it with `stdout.flush()` statements, but it sounds like a logic issue and not a buffering issue. Can't really say without seeing any code. – U2EF1 Jun 06 '13 at 18:19
  • I suspect Python automatically detects it is run non-interactively (in a pipe) and applies some heavy buffering to be more performant. [This might help.](http://stackoverflow.com/questions/107705/python-output-buffering) – kqr Jun 06 '13 at 21:47