cross platform (linux/windows) problem

Miah Gregory miah at picsel.com
Mon Mar 4 06:47:03 EST 2002


In message <u664ibmwn.fsf at ctwd0143.fitlinxx.com>
          David Bolen <db3l at fitlinxx.com> wrote:

> Miah Gregory <miah at picsel.com> writes:

> > Simple example which works for linux:

> You may need to have some per-platform support, since I do think you
> need to use the popen2.Popen3 class under Unix to get exit codes, but
> that isn't supported under Windows.

Strangeness.. I'm getting exit codes under windows ok, just not in the
expected format. This is with os.popen3.

> Note that your sample Linux code might have a problem in that you
> don't drain the output from the piped child until you've gotten an
> exit code, but if the child generates more output than the system
> pipes can buffer, the child may block and never exit until you drain
> the data.  Unless you know the output from the child is limited, I'd
> suggest draining the data as it runs (even if you just save it for
> later use).

As far as output goes, I'm only expecting about 1k of text, max. If it does
start to play up, I'll start reading, as you suggest.

> Under Windows, you should just be able to use os.popen3 directly.  Do
> the same draining of data until the process exits.  Then close the
> files you received from os.popen3 - the final one you close (from the
> full set of stdin/stdout/stderr) will return the exit code of the
> child process.

Yes, os.popen3 seems to work fine. Unfortunately, it's not available in
python 1.5.2, which I have on my linux machine.

-- 
Miah Gregory



More information about the Python-list mailing list