os.system() or os.execv() w/stdout redirect and PID tracking

Gordon McMillan gmcm at hypernet.com
Fri May 7 09:08:16 EDT 1999


The /F-bot wrote:

> Michael Olivier wrote:

[about my literal C to Python xlation of a common idiom, which is 
probably not mine, but I don't recall who I stole it from...]

> > You close stdout with os.close(1) -- os.dup() then just happens to fill
> > in the stdout slot in the table because it's available. Scary coding if
> > true.
> 
> quoting the "single unix specification":

[/F-bot's characteristically authoritative quote snipped]

> so if it doesn't work this way, it sure ain't Unix.  it isn't
> Windows either, for that matter.  and Gordon even
> checks to make sure you don't run this on a system
> that supports "fork" but doesn't handle i/o streams
> correctly.  hardly what I'd call scary coding...

One could use os.dup2 to make it look slightly less scary. But it's 
really only dangerous in the presence of threads, and you're in deep 
doo-doo if you try to fork/exec from a threaded program...

- Gordon




More information about the Python-list mailing list