How to unbuffer Python's output

Chris Rebert clp2 at
Tue Jul 14 05:25:15 EDT 2009

2009/7/13 Lily Gao <Lily.Gao at>:
> Hi, All
> I am calling a python program in perl and use redirection,
> Like :
> `python > 1.log 2>&1`
> When crash, I get nothing from 1.log, and if I don’t use redirection, I
> can get useful log from the screen.
> How can I do to make ‘s  output un-buffered when redirection log to
> files ,just exactly same with print to the screen?

Use the -u flag to python:
−u    Force stdin, stdout and stderr to be totally unbuffered.

python -u > 1.log 2>&1


More information about the Python-list mailing list