Redirecting Python Output to File

February 13, 2010

I have a script that is written in python, and I have a wrapper script in csh that runs the python. As part of the csh script it redirects stdout to a file for logging purposes.

We had a problem where this log file wouldn't be written to until the python process was stopped. This is due to the fact that python buffers stdout.

To get around this problem, you can run python with the -u command line option. See for more details.

Tags: python stdout buffer