Commit 0c96ad4e authored by Fred Drake's avatar Fred Drake

Straighten out the exec*() function descriptions a bit, and clarify a few

points in the spawn*() description.
parent 2e6facf7
...@@ -867,52 +867,50 @@ for \constant{SIGABRT} will behave differently. ...@@ -867,52 +867,50 @@ for \constant{SIGABRT} will behave differently.
Availability: \UNIX, Windows. Availability: \UNIX, Windows.
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{execl}{path, arg0, arg1, ...} \begin{funcdesc}{execl}{path, arg0, arg1, \moreargs}
This is equivalent to \funcline{execle}{path, arg0, arg1, \moreargs, env}
\samp{execv(\var{path}, (\var{arg0}, \var{arg1}, ...))}. \funcline{execlp}{file, arg0, arg1, \moreargs}
Availability: \UNIX{}, Windows. \funcline{execlpe}{file, arg0, arg1, \moreargs, env}
\end{funcdesc} \funcline{execv}{path, args}
\funcline{execve}{path, args, env}
\begin{funcdesc}{execle}{path, arg0, arg1, ..., env} \funcline{execvp}{file, args}
This is equivalent to \funcline{execvpe}{file, args, env}
\samp{execve(\var{path}, (\var{arg0}, \var{arg1}, ...), \var{env})}. These functions all execute a new program, replacing the current
Availability: \UNIX{}, Windows. process; they do not return. On \UNIX, the new executable is loaded
\end{funcdesc} into the current process, and will have the same process ID as the
caller. Errors will be reported as \exception{OSError} exceptions.
\begin{funcdesc}{execlp}{path, arg0, arg1, ...}
This is equivalent to
\samp{execvp(\var{path}, (\var{arg0}, \var{arg1}, ...))}.
Availability: \UNIX{}, Windows.
\end{funcdesc}
\begin{funcdesc}{execv}{path, args} The \character{l} and \character{v} variants of the
Execute the executable \var{path} with argument list \var{args}, \function{exec*()} functions differ in how command-line arguments are
replacing the current process (the Python interpreter). passed. The \character{l} variants are perhaps the easiest to work
The argument list may be a tuple or list of strings. with if the number of parameters is fixed when the code is written;
Availability: \UNIX{}, Windows. the individual parameters simply become additional parameters to the
\end{funcdesc} \function{execl*()} functions. The \character{v} variants are good
when the number of parameters is variable, with the arguments being
\begin{funcdesc}{execve}{path, args, env} passed in a list or tuple as the \var{args} parameter. In either
Execute the executable \var{path} with argument list \var{args}, case, the arguments to the child process must start with the name of
and environment \var{env}, replacing the current process (the Python the command being run.
interpreter).
The argument list may be a tuple or list of strings.
The environment must be a dictionary mapping strings to strings.
Availability: \UNIX{}, Windows.
\end{funcdesc}
\begin{funcdesc}{execvp}{path, args}
This is like \samp{execv(\var{path}, \var{args})} but duplicates
the shell's actions in searching for an executable file in a list of
directories. The directory list is obtained from
\code{environ['PATH']}.
Availability: \UNIX{}, Windows.
\end{funcdesc}
\begin{funcdesc}{execvpe}{path, args, env} The variants which include a \character{p} near the end
This is a cross between \function{execve()} and \function{execvp()}. (\function{execlp()}, \function{execlpe()}, \function{execvp()},
The directory list is obtained from \code{\var{env}['PATH']}. and \function{execvpe()}) will use the \envvar{PATH} environment
Availability: \UNIX{}, Windows. variable to locate the program \var{file}. When the environment is
being replaced (using one of the \function{exec*e()} variants,
discussed in the next paragraph), the
new environment is used as the source of the \envvar{PATH} variable.
The other variants, \function{execl()}, \function{execle()},
\function{execv()}, and \function{execve()}, will not use the
\envvar{PATH} variable to locate the executable; \var{path} must
contain an appropriate absolute or relative path.
For \function{execle()}, \function{execlpe()}, \function{execve()},
and \function{execvpe()} (note that these all end in \character{e}),
the \var{env} parameter must be a mapping which is used to define the
environment variables for the new process; the \function{execl()},
\function{execlp()}, \function{execv()}, and \function{execvp()}
all cause the new process to inherit the environment of the current
process.
Availability: \UNIX, Windows.
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{_exit}{n} \begin{funcdesc}{_exit}{n}
...@@ -970,34 +968,18 @@ functions are described in section \ref{os-newstreams}. ...@@ -970,34 +968,18 @@ functions are described in section \ref{os-newstreams}.
\begin{funcdesc}{spawnl}{mode, path, \moreargs} \begin{funcdesc}{spawnl}{mode, path, \moreargs}
\funcline{spawnle}{mode, path, \moreargs, env} \funcline{spawnle}{mode, path, \moreargs, env}
\funcline{spawnlp}{mode, path, \moreargs} \funcline{spawnlp}{mode, file, \moreargs}
\funcline{spawnlpe}{mode, path, \moreargs, env} \funcline{spawnlpe}{mode, file, \moreargs, env}
\funcline{spawnv}{mode, path, args} \funcline{spawnv}{mode, path, args}
\funcline{spawnve}{mode, path, args, env} \funcline{spawnve}{mode, path, args, env}
\funcline{spawnvp}{mode, path, args} \funcline{spawnvp}{mode, file, args}
\funcline{spawnvpe}{mode, path, 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. 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; it \var{mode} is \constant{P_WAIT}, returns the process's process; it \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
\var{signal} is the signal that killed the process. \var{signal} is the signal that killed the process.
For \function{spawnle()}, \function{spawnlpe()}, \function{spawnve()},
and \function{spawnvpe()} (note that these all end in \character{e}),
the \var{env} parameter must be a mapping which is used to define the
environment variables for the new process; the \function{spawnl()},
\function{spawnlp()}, \function{spawnv()}, and \function{spawnvp()}
all cause the new process to inherit the environment of the current
process.
The variants which include a second \character{p} near the end
(\function{spawnlp()}, \function{spawnlpe()}, \function{spawnvp()},
and \function{spawnvpe()}) will use the \envvar{PATH} environment
variable to locate the program \var{path}. The other variants,
\function{spawnl()}, \function{spawnle()}, \function{spawnv()}, and
\function{spawnve()}, will not use the \envvar{PATH} variable to
locate the executable.
The \character{l} and \character{v} variants of the The \character{l} and \character{v} variants of the
\function{spawn*()} functions differ in how command-line arguments are \function{spawn*()} functions differ in how command-line arguments are
passed. The \character{l} variants are perhaps the easiest to work passed. The \character{l} variants are perhaps the easiest to work
...@@ -1009,6 +991,26 @@ passed in a list or tuple as the \var{args} parameter. In either ...@@ -1009,6 +991,26 @@ passed in a list or tuple as the \var{args} parameter. In either
case, the arguments to the child process must start with the name of case, the arguments to the child process must start with the name of
the command being run. the command being run.
The variants which include a second \character{p} near the end
(\function{spawnlp()}, \function{spawnlpe()}, \function{spawnvp()},
and \function{spawnvpe()}) will use the \envvar{PATH} environment
variable to locate the program \var{file}. When the environment is
being replaced (using one of the \function{spawn*e()} variants,
discussed in the next paragraph), the new environment is used as the
source of the \envvar{PATH} variable. The other variants,
\function{spawnl()}, \function{spawnle()}, \function{spawnv()}, and
\function{spawnve()}, will not use the \envvar{PATH} variable to
locate the executable; \var{path} must contain an appropriate absolute
or relative path.
For \function{spawnle()}, \function{spawnlpe()}, \function{spawnve()},
and \function{spawnvpe()} (note that these all end in \character{e}),
the \var{env} parameter must be a mapping which is used to define the
environment variables for the new process; the \function{spawnl()},
\function{spawnlp()}, \function{spawnv()}, and \function{spawnvp()}
all cause the new process to inherit the environment of the current
process.
As an example, the following calls to \function{spawnlp()} and As an example, the following calls to \function{spawnlp()} and
\function{spawnvpe()} are equivalent: \function{spawnvpe()} are equivalent:
...@@ -1020,7 +1022,8 @@ L = ['cp', 'index.html', '/dev/null'] ...@@ -1020,7 +1022,8 @@ L = ['cp', 'index.html', '/dev/null']
os.spawnvpe(os.P_WAIT, 'cp', L, os.environ) os.spawnvpe(os.P_WAIT, 'cp', L, os.environ)
\end{verbatim} \end{verbatim}
Availability: \UNIX{}, Windows. Availability: \UNIX, Windows. \function{spawnvp()} and
\function{spawnvpe()} are not available on Windows.
\versionadded{1.6} \versionadded{1.6}
\end{funcdesc} \end{funcdesc}
......
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