os.system() or os.execv() w/stdout redirect and PID tracking
Fredrik Lundh
fredrik at pythonware.com
Fri May 7 07:11:27 EDT 1999
Michael Olivier wrote:
> Thanks a lot, Gordon! This really helps. It took a little to
> understand the magic hacks going on... is there any cleaner way to refer
> to stdout than as '1'?
> 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":
"At program startup, three streams are predefined
and need not be opened explicitly: standard input
(for reading conventional input), standard output
(for writing conventional output), and standard
error (for writing diagnostic output)."
"The following symbolic constants are defined for file
streams:
STDIN_FILENO
File number of stdin. It is 0.
STDOUT_FILENO
File number of stdout. It is 1.
STDERR_FILENO
File number of stderr. It is 2."
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...
</F>
More information about the Python-list
mailing list