Kaydet (Commit) d3aad019 authored tarafından Andrew M. Kuchling's avatar Andrew M. Kuchling

Point users to the subprocess module in the docs for os.system, os.spawn*,…

Point users to the subprocess module in the docs for os.system, os.spawn*, os.popen2, and the popen2 and commands modules
üst 1f3ebe0b
...@@ -12,6 +12,11 @@ The \module{commands} module contains wrapper functions for ...@@ -12,6 +12,11 @@ The \module{commands} module contains wrapper functions for
return any output generated by the command and, optionally, the exit return any output generated by the command and, optionally, the exit
status. status.
The \module{subprocess} module provides more powerful facilities for
spawning new processes and retrieving their results. Using the
\module{subprocess} module is preferable to using the \module{commands}
module.
The \module{commands} module defines the following functions: The \module{commands} module defines the following functions:
...@@ -51,3 +56,7 @@ Example: ...@@ -51,3 +56,7 @@ Example:
>>> commands.getstatus('/bin/ls') >>> commands.getstatus('/bin/ls')
'-rwxr-xr-x 1 root 13352 Oct 14 1994 /bin/ls' '-rwxr-xr-x 1 root 13352 Oct 14 1994 /bin/ls'
\end{verbatim} \end{verbatim}
\begin{seealso}
\seemodule{subprocess}{Module for spawning and managing subprocesses.}
\end{seealso}
...@@ -361,6 +361,10 @@ object, except that when the exit status is zero (termination without ...@@ -361,6 +361,10 @@ object, except that when the exit status is zero (termination without
errors), \code{None} is returned. errors), \code{None} is returned.
Availability: Macintosh, \UNIX, Windows. Availability: Macintosh, \UNIX, Windows.
The \module{subprocess} module provides more powerful facilities for
spawning new processes and retrieving their results; using that module
is preferable to using this function.
\versionchanged[This function worked unreliably under Windows in \versionchanged[This function worked unreliably under Windows in
earlier versions of Python. This was due to the use of the earlier versions of Python. This was due to the use of the
\cfunction{_popen()} function from the libraries provided with \cfunction{_popen()} function from the libraries provided with
...@@ -375,8 +379,13 @@ deleted once there are no file descriptors for the file. ...@@ -375,8 +379,13 @@ deleted once there are no file descriptors for the file.
Availability: Macintosh, \UNIX, Windows. Availability: Macintosh, \UNIX, Windows.
\end{funcdesc} \end{funcdesc}
There are a number of different \function{popen*()} functions that
provide slightly different ways to create subprocesses. Note that the
\module{subprocess} module is easier to use and more powerful;
consider using that module before writing code using the
lower-level \function{popen*()} functions.
For each of the following \function{popen()} variants, if \var{bufsize} is For each of the \function{popen*()} variants, if \var{bufsize} is
specified, it specifies the buffer size for the I/O pipes. specified, it specifies the buffer size for the I/O pipes.
\var{mode}, if provided, should be the string \code{'b'} or \var{mode}, if provided, should be the string \code{'b'} or
\code{'t'}; on Windows this is needed to determine whether the file \code{'t'}; on Windows this is needed to determine whether the file
...@@ -1547,7 +1556,13 @@ functions are described in section \ref{os-newstreams}. ...@@ -1547,7 +1556,13 @@ functions are described in section \ref{os-newstreams}.
\funcline{spawnve}{mode, path, args, env} \funcline{spawnve}{mode, path, args, env}
\funcline{spawnvp}{mode, file, args} \funcline{spawnvp}{mode, file, args}
\funcline{spawnvpe}{mode, file, args, env} \funcline{spawnvpe}{mode, file, args, env}
Execute the program \var{path} in a new process. If \var{mode} is Execute the program \var{path} in a new process.
(Note that the \module{subprocess} module provides more powerful
facilities for spawning new processes and retrieving their results;
using that module is preferable to using these functions.)
If \var{mode} is
\constant{P_NOWAIT}, this function returns the process ID of the new \constant{P_NOWAIT}, this function returns the process ID of the new
process; if \var{mode} is \constant{P_WAIT}, returns the process's process; if \var{mode} is \constant{P_WAIT}, returns the process's
exit code if it exits normally, or \code{-\var{signal}}, where exit code if it exits normally, or \code{-\var{signal}}, where
...@@ -1684,6 +1699,10 @@ and XP) this is the exit status of the command run; on systems using ...@@ -1684,6 +1699,10 @@ and XP) this is the exit status of the command run; on systems using
a non-native shell, consult your shell documentation. a non-native shell, consult your shell documentation.
Availability: Macintosh, \UNIX, Windows. Availability: Macintosh, \UNIX, Windows.
The \module{subprocess} module provides more powerful facilities for
spawning new processes and retrieving their results; using that module
is preferable to using this function.
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{times}{} \begin{funcdesc}{times}{}
......
...@@ -11,10 +11,10 @@ This module allows you to spawn processes and connect to their ...@@ -11,10 +11,10 @@ This module allows you to spawn processes and connect to their
input/output/error pipes and obtain their return codes under input/output/error pipes and obtain their return codes under
\UNIX{} and Windows. \UNIX{} and Windows.
Note that starting with Python 2.0, this functionality is available The \module{subprocess} module provides more powerful facilities for
using functions from the \refmodule{os} module which have the same spawning new processes and retrieving their results. Using the
names as the factory functions here, but the order of the return \module{subprocess} module is preferable to using the \module{popen2}
values is more intuitive in the \refmodule{os} module variants. module.
The primary interface offered by this module is a trio of factory The primary interface offered by this module is a trio of factory
functions. For each of these, if \var{bufsize} is specified, functions. For each of these, if \var{bufsize} is specified,
...@@ -184,3 +184,7 @@ integrate I/O over pipes with their \function{select()} loops, or use ...@@ -184,3 +184,7 @@ integrate I/O over pipes with their \function{select()} loops, or use
separate threads to read each of the individual files provided by separate threads to read each of the individual files provided by
whichever \function{popen*()} function or \class{Popen*} class was whichever \function{popen*()} function or \class{Popen*} class was
used. used.
\begin{seealso}
\seemodule{subprocess}{Module for spawning and managing subprocesses.}
\end{seealso}
...@@ -12,9 +12,6 @@ connect to their input/output/error pipes, and obtain their return ...@@ -12,9 +12,6 @@ connect to their input/output/error pipes, and obtain their return
codes. This module intends to replace several other, older modules codes. This module intends to replace several other, older modules
and functions, such as: and functions, such as:
% XXX Should add pointers to this module to at least the popen2
% and commands sections.
\begin{verbatim} \begin{verbatim}
os.system os.system
os.spawn* os.spawn*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment