python - How to write script output to file and command-line? -


I have a long running Python script that I run from the command line. The script writes progress messages and results for the standard output. I want to capture the scripts that are written on standard output in a file, but I want to see it on the command line also. Alternatively, I have to go to the output immediately in the file, so I can use the tail to see the progress. I have tried this:

  Python MyLongRunngingScripts.py | T log Txt  

but it does not produce any output (just run the script as it produces the output as expected). Can anyone offer a simple solution? I'm using Mac OS X 10.6.4.

Edit I am using print for output in my script.

You are on the right track but the problem is that buffering the output.

Fortunately, there is a way to not tell buffer output:

  Python-i MyLongRunnging script.py | T log Txt  

Comments