``'exec'`` if *source* consists of a sequence of statements, ``'eval'`` if it
consists of a single expression, or ``'single'`` if it consists of a single
interactive statement (in the latter case, expression statements that
- evaluate to something else than ``None`` will be printed).
+ evaluate to something other than ``None`` will be printed).
The optional arguments *flags* and *dont_inherit* control which future
statements (see :pep:`236`) affect the compilation of *source*. If neither
(Note that the :mod:`subprocess` module provides more powerful facilities for
spawning new processes and retrieving their results; using that module is
- preferable to using these functions. Check specially the *Replacing Older
- Functions with the subprocess Module* section in that documentation page.)
+ preferable to using these functions. Check especially the
+ :ref:`subprocess-replacements` section.)
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
Arguments are:
*args* should be a string, or a sequence of program arguments. The program
- to execute is normally the first item in the args sequence or the string if a
- string is given, but can be explicitly set by using the *executable*
- argument.
+ to execute is normally the first item in the args sequence or the string if
+ a string is given, but can be explicitly set by using the *executable*
+ argument. When *executable* is given, the first item in the args sequence
+ is still treated by most programs as the command name, which can then be
+ different from the actual executable name. On Unix, it becomes the display
+ name for the executing program in utilities such as :program:`ps`.
On Unix, with *shell=False* (default): In this case, the Popen class uses
:meth:`os.execvp` to execute the child program. *args* should normally be a
output = p2.communicate()[0]
-Replacing os.system()
-^^^^^^^^^^^^^^^^^^^^^
+Replacing :func:`os.system`
+^^^^^^^^^^^^^^^^^^^^^^^^^^^
::
print >>sys.stderr, "Execution failed:", e
-Replacing the os.spawn family
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+Replacing the :func:`os.spawn <os.spawnl>` family
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
P_NOWAIT 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`
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
::
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::