How to unbuffer Python's output

Chris Rebert clp2 at rebertia.com
Tue Jul 14 11:25:15 CEST 2009


2009/7/13 Lily Gao <Lily.Gao at autodesk.com>:
> Hi, All
>
> I am calling a python program in perl and use redirection,
>
> Like :
>
> `python x.py > 1.log 2>&1`
>
> When x.py 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 x.py ‘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 x.py > 1.log 2>&1

Cheers,
Chris
-- 
http://blog.rebertia.com



More information about the Python-list mailing list