cross platform (linux/windows) problem

David Bolen db3l at fitlinxx.com
Wed Feb 27 17:06:00 EST 2002


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.

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).

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.

--
-- David
-- 
/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: db3l at fitlinxx.com  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/



More information about the Python-list mailing list