Mailing List Archive

CVS: python/dist/src/Doc/lib libos.tex,1.63,1.64 libpopen2.tex,1.14,1.15
Update of /cvsroot/python/python/dist/src/Doc/lib
In directory usw-pr-cvs1:/tmp/cvs-serv5964/lib

Modified Files:
libos.tex libpopen2.tex
Log Message:
Document clearly that the only way to retrieve the return code from the
child processes is to use the Popen3 and Popen4 classes.
This fixes SF bug #460512.


Index: libos.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/lib/libos.tex,v
retrieving revision 1.63
retrieving revision 1.64
diff -C2 -d -r1.63 -r1.64
*** libos.tex 2001/08/16 21:21:28 1.63
--- libos.tex 2001/09/11 19:56:51 1.64
***************
*** 316,319 ****
--- 316,325 ----
for \var{mode} is \code{'t'}.

+ These methods do not make it possible to retrieve the return code from
+ the child processes. The only way to control the input and output
+ streams and also retrieve the return codes is to use the
+ \class{Popen3} and \class{Popen4} classes from the \refmodule{popen2}
+ module; these are only available on \UNIX.
+
\begin{funcdesc}{popen2}{cmd\optional{, mode\optional{, bufsize}}}
Executes \var{cmd} as a sub-process. Returns the file objects

Index: libpopen2.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/lib/libpopen2.tex,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** libpopen2.tex 2001/07/06 17:17:12 1.14
--- libpopen2.tex 2001/09/11 19:56:51 1.15
***************
*** 25,28 ****
--- 25,35 ----
\code{'t'}.

+ The only way to retrieve the return codes for the child processes is
+ by using the \method{poll()} or \method{wait()} methods on the
+ \class{Popen3} and \class{Popen4} classes; these are only available on
+ \UNIX. This information is not available when using the
+ \function{popen2()}, \function{popen3()}, and \function{popen4()}
+ functions, or the equivalent functions in the \refmodule{os} module.
+
\begin{funcdesc}{popen2}{cmd\optional{, bufsize\optional{, mode}}}
Executes \var{cmd} as a sub-process. Returns the file objects
RE: CVS: python/dist/src/Doc/lib libos.tex,1.63,1.64 libpopen2.tex,1.14,1.15 [ In reply to ]
[Fred L. Drake]
> + These methods do not make it possible to retrieve the return code from
> + the child processes. The only way to control the input and output
> + streams and also retrieve the return codes is to use the
> + \class{Popen3} and \class{Popen4} classes from the \refmodule{popen2}
> + module; these are only available on \UNIX.

I'm not sure that's true, but don't know. Mark Hammond seemed to believe
you can get them on Windows (and also Unix?) from the value returned by
e.close() where e is the stderr object returned by these functions (in
analogy with how plain popen works).
RE: CVS: python/dist/src/Doc/lib libos.tex,1.63,1.64 libpopen2.tex,1.14,1.15 [ In reply to ]
Tim Peters writes:
> I'm not sure that's true, but don't know. Mark Hammond seemed to believe
> you can get them on Windows (and also Unix?) from the value returned by
> e.close() where e is the stderr object returned by these functions (in
> analogy with how plain popen works).

This does not appear to be the case on Linux:

>>> import popen2
>>> childout, childin = popen2.popen2("cat foo")
>>> cat: foo: No such file or directory
childin
<open file '(fdopen)', mode 'w' at 0x815d528>
>>> childin.close()
>>> childout.close()

[None returned from both close() methods.]
Looking at the code in popen2, I don't see any way to dig the return
code out unless something is done to ensure the Popen3/4 object is
kept alive and the close() methods of the file object automagically
called the wait() method. It might be possible, but the code as
written does not support this on Unix.


-Fred

--
Fred L. Drake, Jr. <fdrake at acm.org>
PythonLabs at Zope Corporation