diff options
author | R. David Murray <rdmurray@bitdance.com> | 2009-06-09 00:44:22 (GMT) |
---|---|---|
committer | R. David Murray <rdmurray@bitdance.com> | 2009-06-09 00:44:22 (GMT) |
commit | ccb9d4b21c37183c1e2e10cd14e4f734157c153f (patch) | |
tree | 73c50af7f340a9b8580f1684569f108b578fef59 /Doc/library/subprocess.rst | |
parent | a5a5728cf01446f70c3bd09cc85453fdec71d461 (diff) | |
download | cpython-ccb9d4b21c37183c1e2e10cd14e4f734157c153f.zip cpython-ccb9d4b21c37183c1e2e10cd14e4f734157c153f.tar.gz cpython-ccb9d4b21c37183c1e2e10cd14e4f734157c153f.tar.bz2 |
Issue 2947: document how return code handling translates from
os.popen to subprocess. Also fixes reference link in the
os.spawn documentation.
Diffstat (limited to 'Doc/library/subprocess.rst')
-rw-r--r-- | Doc/library/subprocess.rst | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/Doc/library/subprocess.rst b/Doc/library/subprocess.rst index 73c622e..e5a86e6 100644 --- a/Doc/library/subprocess.rst +++ b/Doc/library/subprocess.rst @@ -392,8 +392,8 @@ Replacing shell pipeline 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 -Replacing the os.spawn family -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Replacing the :func:`os.spawn <os.spawnl>` family +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ P_NOWAIT example:: @@ -448,8 +448,8 @@ Environment example:: 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) (child_stdin, child_stdout_and_stderr) = (p.stdin, p.stdout) +Return code handling translates as follows:: + + 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 popen2 module -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Replacing functions from the :mod:`popen2` module +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. note:: |