redirecting stderr back..
steve at holdenweb.com
Tue Jan 13 03:14:28 CET 2009
Дамјан Георгиевски wrote:
>> Hi All,
>> Can someone tell me how to redirect stderr back to the console once
>> you've moved it?
>> import os,sys
>> se = os.open("/tmp/mod.log", os.O_WRONLY|os.O_APPEND|os.O_CREAT)
>> os.dup2(se, 2)
> why not os.dup2(2, 10) and then later os.dup2(10, 2)
I'd have thought it would be necessary to do something like that in the
general case to ensure that the original standard error remained open.
os.dup2 will close the original file unless it's still open on another
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
More information about the Python-list