Issue 2947: document how return code handling translates from
os.popen to subprocess. Also fixes reference link in the os.spawn documentation.
This commit is contained in:
parent
a5a5728cf0
commit
ccb9d4b21c
|
@ -1715,8 +1715,8 @@ written in Python, such as a mail server's external command delivery program.
|
||||||
|
|
||||||
(Note that the :mod:`subprocess` module provides more powerful facilities for
|
(Note that the :mod:`subprocess` module provides more powerful facilities for
|
||||||
spawning new processes and retrieving their results; using that module is
|
spawning new processes and retrieving their results; using that module is
|
||||||
preferable to using these functions. Check specially the *Replacing Older
|
preferable to using these functions. Check especially the
|
||||||
Functions with the subprocess Module* section in that documentation page.)
|
:ref:`subprocess-replacements` section.)
|
||||||
|
|
||||||
If *mode* is :const:`P_NOWAIT`, this function returns the process id of the new
|
If *mode* is :const:`P_NOWAIT`, this function returns the process id of the new
|
||||||
process; if *mode* is :const:`P_WAIT`, returns the process's exit code if it
|
process; if *mode* is :const:`P_WAIT`, returns the process's exit code if it
|
||||||
|
|
|
@ -392,8 +392,8 @@ Replacing shell pipeline
|
||||||
output = p2.communicate()[0]
|
output = p2.communicate()[0]
|
||||||
|
|
||||||
|
|
||||||
Replacing os.system()
|
Replacing :func:`os.system`
|
||||||
^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
|
@ -420,8 +420,8 @@ A more realistic example would look like this::
|
||||||
print >>sys.stderr, "Execution failed:", e
|
print >>sys.stderr, "Execution failed:", e
|
||||||
|
|
||||||
|
|
||||||
Replacing the os.spawn family
|
Replacing the :func:`os.spawn <os.spawnl>` family
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
P_NOWAIT example::
|
P_NOWAIT example::
|
||||||
|
|
||||||
|
@ -448,8 +448,8 @@ Environment example::
|
||||||
Popen(["/bin/mycmd", "myarg"], env={"PATH": "/usr/bin"})
|
Popen(["/bin/mycmd", "myarg"], env={"PATH": "/usr/bin"})
|
||||||
|
|
||||||
|
|
||||||
Replacing os.popen, os.popen2, os.popen3
|
Replacing :func:`os.popen`, :func:`os.popen2`, :func:`os.popen3`
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
|
@ -491,9 +491,23 @@ Replacing os.popen, os.popen2, os.popen3
|
||||||
stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
|
stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
|
||||||
(child_stdin, child_stdout_and_stderr) = (p.stdin, p.stdout)
|
(child_stdin, child_stdout_and_stderr) = (p.stdin, p.stdout)
|
||||||
|
|
||||||
|
Return code handling translates as follows::
|
||||||
|
|
||||||
Replacing functions from the popen2 module
|
pipe = os.popen(cmd, 'w')
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
...
|
||||||
|
rc = pipe.close()
|
||||||
|
if rc != None and rc % 256:
|
||||||
|
print "There were some errors"
|
||||||
|
==>
|
||||||
|
process = Popen(cmd, 'w', stdin=PIPE)
|
||||||
|
...
|
||||||
|
process.stdin.close()
|
||||||
|
if process.wait() != 0:
|
||||||
|
print "There were some errors"
|
||||||
|
|
||||||
|
|
||||||
|
Replacing functions from the :mod:`popen2` module
|
||||||
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue