2007-08-15 11:28:01 -03:00
|
|
|
|
|
|
|
:mod:`subprocess` --- Subprocess management
|
|
|
|
===========================================
|
|
|
|
|
|
|
|
.. module:: subprocess
|
|
|
|
:synopsis: Subprocess management.
|
|
|
|
.. moduleauthor:: Peter Åstrand <astrand@lysator.liu.se>
|
|
|
|
.. sectionauthor:: Peter Åstrand <astrand@lysator.liu.se>
|
|
|
|
|
|
|
|
|
|
|
|
.. versionadded:: 2.4
|
|
|
|
|
|
|
|
The :mod:`subprocess` module allows you to spawn new processes, connect to their
|
|
|
|
input/output/error pipes, and obtain their return codes. This module intends to
|
|
|
|
replace several other, older modules and functions, such as::
|
|
|
|
|
|
|
|
os.system
|
|
|
|
os.spawn*
|
|
|
|
os.popen*
|
|
|
|
popen2.*
|
|
|
|
commands.*
|
|
|
|
|
|
|
|
Information about how the :mod:`subprocess` module can be used to replace these
|
|
|
|
modules and functions can be found in the following sections.
|
|
|
|
|
2008-07-01 16:59:00 -03:00
|
|
|
.. seealso::
|
|
|
|
|
|
|
|
:pep:`324` -- PEP proposing the subprocess module
|
|
|
|
|
2007-08-15 11:28:01 -03:00
|
|
|
|
|
|
|
Using the subprocess Module
|
|
|
|
---------------------------
|
|
|
|
|
|
|
|
This module defines one class called :class:`Popen`:
|
|
|
|
|
|
|
|
|
|
|
|
.. class:: Popen(args, bufsize=0, executable=None, stdin=None, stdout=None, stderr=None, preexec_fn=None, close_fds=False, shell=False, cwd=None, env=None, universal_newlines=False, startupinfo=None, creationflags=0)
|
|
|
|
|
|
|
|
Arguments are:
|
|
|
|
|
2008-07-27 12:22:14 -03:00
|
|
|
*args* should be a string, or a sequence of program arguments. The program
|
2009-06-25 14:40:52 -03:00
|
|
|
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`.
|
2007-08-15 11:28:01 -03:00
|
|
|
|
|
|
|
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
|
2010-02-04 12:35:33 -04:00
|
|
|
sequence. If a string is specified for *args*, it will be used as the name
|
|
|
|
or path of the program to execute; this will only work if the program is
|
|
|
|
being given no arguments.
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
:meth:`shlex.split` can be useful when determining the correct
|
|
|
|
tokenization for *args*, especially in complex cases::
|
|
|
|
|
|
|
|
>>> import shlex, subprocess
|
|
|
|
>>> command_line = raw_input()
|
|
|
|
/bin/vikings -input eggs.txt -output "spam spam.txt" -cmd "echo '$MONEY'"
|
|
|
|
>>> args = shlex.split(command_line)
|
|
|
|
>>> print args
|
|
|
|
['/bin/vikings', '-input', 'eggs.txt', '-output', 'spam spam.txt', '-cmd', "echo '$MONEY'"]
|
|
|
|
>>> p = subprocess.Popen(args) # Success!
|
|
|
|
|
|
|
|
Note in particular that options (such as *-input*) and arguments (such
|
|
|
|
as *eggs.txt*) that are separated by whitespace in the shell go in separate
|
|
|
|
list elements, while arguments that need quoting or backslash escaping when
|
|
|
|
used in the shell (such as filenames containing spaces or the *echo* command
|
|
|
|
shown above) are single list elements.
|
|
|
|
|
|
|
|
On Unix, with *shell=True*: If args is a string, it specifies the command
|
|
|
|
string to execute through the shell. This means that the string must be
|
|
|
|
formatted exactly as it would be when typed at the shell prompt. This
|
|
|
|
includes, for example, quoting or backslash escaping filenames with spaces in
|
|
|
|
them. If *args* is a sequence, the first item specifies the command string, and
|
|
|
|
any additional items will be treated as additional arguments to the shell
|
|
|
|
itself. That is to say, *Popen* does the equivalent of::
|
|
|
|
|
|
|
|
Popen(['/bin/sh', '-c', args[0], args[1], ...])
|
2007-08-15 11:28:01 -03:00
|
|
|
|
|
|
|
On Windows: the :class:`Popen` class uses CreateProcess() to execute the child
|
|
|
|
program, which operates on strings. If *args* is a sequence, it will be
|
|
|
|
converted to a string using the :meth:`list2cmdline` method. Please note that
|
|
|
|
not all MS Windows applications interpret the command line the same way:
|
|
|
|
:meth:`list2cmdline` is designed for applications using the same rules as the MS
|
|
|
|
C runtime.
|
|
|
|
|
|
|
|
*bufsize*, if given, has the same meaning as the corresponding argument to the
|
|
|
|
built-in open() function: :const:`0` means unbuffered, :const:`1` means line
|
|
|
|
buffered, any other positive value means use a buffer of (approximately) that
|
|
|
|
size. A negative *bufsize* means to use the system default, which usually means
|
|
|
|
fully buffered. The default value for *bufsize* is :const:`0` (unbuffered).
|
|
|
|
|
|
|
|
The *executable* argument specifies the program to execute. It is very seldom
|
|
|
|
needed: Usually, the program to execute is defined by the *args* argument. If
|
|
|
|
``shell=True``, the *executable* argument specifies which shell to use. On Unix,
|
|
|
|
the default shell is :file:`/bin/sh`. On Windows, the default shell is
|
Merged revisions 73286,73294,73296,73459,73462-73463,73544,73576-73577,73595-73596,73693-73694,73704-73705,73707,73713,73937-73940,73945,73951,73979 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r73286 | georg.brandl | 2009-06-08 09:57:35 +0200 (Mo, 08 Jun 2009) | 1 line
Remove period from end of headings.
........
r73294 | georg.brandl | 2009-06-08 15:34:52 +0200 (Mo, 08 Jun 2009) | 1 line
#6194: O_SHLOCK/O_EXLOCK are not really more platform independent than lockf().
........
r73296 | georg.brandl | 2009-06-08 18:03:41 +0200 (Mo, 08 Jun 2009) | 1 line
#6238: add fillchar to string.just function family.
........
r73459 | raymond.hettinger | 2009-06-17 03:43:47 +0200 (Mi, 17 Jun 2009) | 1 line
Add usage note.
........
r73462 | georg.brandl | 2009-06-17 11:36:21 +0200 (Mi, 17 Jun 2009) | 1 line
#6295: clarify blocking behavior of getch().
........
r73463 | georg.brandl | 2009-06-17 11:43:31 +0200 (Mi, 17 Jun 2009) | 1 line
#6255: document PyInt_FromSize_t.
........
r73544 | georg.brandl | 2009-06-24 08:41:19 +0200 (Mi, 24 Jun 2009) | 1 line
#6332: fix word dupes throughout the source.
........
r73576 | benjamin.peterson | 2009-06-27 01:37:06 +0200 (Sa, 27 Jun 2009) | 1 line
document is_declared_global()
........
r73577 | benjamin.peterson | 2009-06-27 16:16:23 +0200 (Sa, 27 Jun 2009) | 1 line
link to extensive generator docs in the reference manual
........
r73595 | ezio.melotti | 2009-06-28 01:45:39 +0200 (So, 28 Jun 2009) | 1 line
stmt and setup can contain multiple statements, see #5896
........
r73596 | ezio.melotti | 2009-06-28 02:07:45 +0200 (So, 28 Jun 2009) | 1 line
Fixed a wrong apostrophe
........
r73693 | jesse.noller | 2009-06-29 20:20:34 +0200 (Mo, 29 Jun 2009) | 1 line
Bug 5906: add a documentation note for unix daemons vs. multiprocessing daemons
........
r73694 | jesse.noller | 2009-06-29 20:24:26 +0200 (Mo, 29 Jun 2009) | 1 line
Issue 5740: multiprocessing.connection.* authkey fixes
........
r73704 | georg.brandl | 2009-06-30 18:15:43 +0200 (Di, 30 Jun 2009) | 1 line
#6376: fix copy-n-paste oversight.
........
r73705 | georg.brandl | 2009-06-30 18:17:28 +0200 (Di, 30 Jun 2009) | 1 line
#6374: add a bit of explanation about shell=True on Windows.
........
r73707 | georg.brandl | 2009-06-30 18:35:11 +0200 (Di, 30 Jun 2009) | 1 line
#6371: fix link targets.
........
r73713 | ezio.melotti | 2009-07-01 00:56:16 +0200 (Mi, 01 Jul 2009) | 1 line
Fixed a backslash that was not supposed to be there
........
r73937 | georg.brandl | 2009-07-11 12:12:36 +0200 (Sa, 11 Jul 2009) | 1 line
Fix style.
........
r73938 | georg.brandl | 2009-07-11 12:14:54 +0200 (Sa, 11 Jul 2009) | 1 line
#6446: fix import_spam() function to use correct error and reference handling.
........
r73939 | georg.brandl | 2009-07-11 12:18:10 +0200 (Sa, 11 Jul 2009) | 1 line
#6448: clarify docs for find_module().
........
r73940 | georg.brandl | 2009-07-11 12:37:38 +0200 (Sa, 11 Jul 2009) | 1 line
#6430: add note about size of "u" type.
........
r73945 | georg.brandl | 2009-07-11 12:51:31 +0200 (Sa, 11 Jul 2009) | 1 line
#6456: clarify the meaning of constants used as arguments to nl_langinfo().
........
r73951 | georg.brandl | 2009-07-11 16:23:38 +0200 (Sa, 11 Jul 2009) | 2 lines
array.array is actually a class.
........
r73979 | benjamin.peterson | 2009-07-12 18:56:54 +0200 (So, 12 Jul 2009) | 1 line
add versionadded
........
2009-10-27 11:29:22 -03:00
|
|
|
specified by the :envvar:`COMSPEC` environment variable. The only reason you
|
|
|
|
would need to specify ``shell=True`` on Windows is where the command you
|
|
|
|
wish to execute is actually built in to the shell, eg ``dir``, ``copy``.
|
|
|
|
You don't need ``shell=True`` to run a batch file, nor to run a console-based
|
|
|
|
executable.
|
2007-08-15 11:28:01 -03:00
|
|
|
|
|
|
|
*stdin*, *stdout* and *stderr* specify the executed programs' standard input,
|
Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r67571 | georg.brandl | 2008-12-05 10:13:45 +0100 (Fri, 05 Dec 2008) | 2 lines
Use markup.
........
r67574 | georg.brandl | 2008-12-05 10:25:32 +0100 (Fri, 05 Dec 2008) | 2 lines
#4441 followup: Add link to open() docs for Windows.
........
r67575 | georg.brandl | 2008-12-05 12:34:51 +0100 (Fri, 05 Dec 2008) | 2 lines
#4544: add `dedent` to textwrap.__all__.
........
r67576 | georg.brandl | 2008-12-05 13:09:41 +0100 (Fri, 05 Dec 2008) | 2 lines
#4529: fix parser's validation for try-except-finally statements.
........
r67579 | georg.brandl | 2008-12-05 16:29:39 +0100 (Fri, 05 Dec 2008) | 2 lines
#4517: add "special method" glossary entry and clarify when __getattribute__ is bypassed.
........
r67580 | georg.brandl | 2008-12-05 16:32:29 +0100 (Fri, 05 Dec 2008) | 2 lines
#4478: document that copyfile() can raise Error.
........
r67581 | georg.brandl | 2008-12-05 16:42:03 +0100 (Fri, 05 Dec 2008) | 2 lines
#3171: document that *slice are removed in 3k.
........
r67583 | georg.brandl | 2008-12-05 16:52:20 +0100 (Fri, 05 Dec 2008) | 4 lines
Move __import__ to the bottom of the functions list.
It doesn't make sense for such a fundamental document to have
the most obscure function listed at the top.
........
r67591 | georg.brandl | 2008-12-05 19:00:06 +0100 (Fri, 05 Dec 2008) | 2 lines
Followup to #4511: add link from decorator glossary entry to definition.
........
r67597 | georg.brandl | 2008-12-05 20:03:19 +0100 (Fri, 05 Dec 2008) | 2 lines
Remove confusing sentence part.
........
r67608 | georg.brandl | 2008-12-06 12:57:12 +0100 (Sat, 06 Dec 2008) | 2 lines
Follow-up to #4488: document PIPE and STDOUT properly.
........
r67631 | georg.brandl | 2008-12-07 12:54:07 +0100 (Sun, 07 Dec 2008) | 2 lines
Add link to the favicon to the docs.
........
2008-12-07 10:47:12 -04:00
|
|
|
standard output and standard error file handles, respectively. Valid values
|
|
|
|
are :data:`PIPE`, an existing file descriptor (a positive integer), an
|
|
|
|
existing file object, and ``None``. :data:`PIPE` indicates that a new pipe
|
|
|
|
to the child should be created. With ``None``, no redirection will occur;
|
|
|
|
the child's file handles will be inherited from the parent. Additionally,
|
|
|
|
*stderr* can be :data:`STDOUT`, which indicates that the stderr data from the
|
|
|
|
applications should be captured into the same file handle as for stdout.
|
2007-08-15 11:28:01 -03:00
|
|
|
|
|
|
|
If *preexec_fn* is set to a callable object, this object will be called in the
|
|
|
|
child process just before the child is executed. (Unix only)
|
|
|
|
|
|
|
|
If *close_fds* is true, all file descriptors except :const:`0`, :const:`1` and
|
|
|
|
:const:`2` will be closed before the child process is executed. (Unix only).
|
|
|
|
Or, on Windows, if *close_fds* is true then no handles will be inherited by the
|
|
|
|
child process. Note that on Windows, you cannot set *close_fds* to true and
|
|
|
|
also redirect the standard handles by setting *stdin*, *stdout* or *stderr*.
|
|
|
|
|
|
|
|
If *shell* is :const:`True`, the specified command will be executed through the
|
|
|
|
shell.
|
|
|
|
|
|
|
|
If *cwd* is not ``None``, the child's current directory will be changed to *cwd*
|
|
|
|
before it is executed. Note that this directory is not considered when
|
|
|
|
searching the executable, so you can't specify the program's path relative to
|
|
|
|
*cwd*.
|
|
|
|
|
2008-04-19 13:58:49 -03:00
|
|
|
If *env* is not ``None``, it must be a mapping that defines the environment
|
|
|
|
variables for the new process; these are used instead of inheriting the current
|
|
|
|
process' environment, which is the default behavior.
|
2007-08-15 11:28:01 -03:00
|
|
|
|
2009-04-16 15:17:55 -03:00
|
|
|
.. note::
|
2009-04-15 19:34:30 -03:00
|
|
|
|
2009-04-16 15:17:55 -03:00
|
|
|
If specified, *env* must provide any variables required
|
|
|
|
for the program to execute. On Windows, in order to run a
|
|
|
|
`side-by-side assembly`_ the specified *env* **must** include a valid
|
2009-04-15 19:34:30 -03:00
|
|
|
:envvar:`SystemRoot`.
|
|
|
|
|
2009-04-16 15:17:55 -03:00
|
|
|
.. _side-by-side assembly: http://en.wikipedia.org/wiki/Side-by-Side_Assembly
|
|
|
|
|
2007-08-15 11:28:01 -03:00
|
|
|
If *universal_newlines* is :const:`True`, the file objects stdout and stderr are
|
|
|
|
opened as text files, but lines may be terminated by any of ``'\n'``, the Unix
|
2008-09-13 14:41:16 -03:00
|
|
|
end-of-line convention, ``'\r'``, the old Macintosh convention or ``'\r\n'``, the
|
2007-08-15 11:28:01 -03:00
|
|
|
Windows convention. All of these external representations are seen as ``'\n'``
|
|
|
|
by the Python program.
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
Merged revisions 76538,76559,76882-76883,76886,76891-76892,76920,76924-76925,77081,77084,77086,77092 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r76538 | georg.brandl | 2009-11-26 21:48:25 +0100 (Do, 26 Nov 2009) | 1 line
#7400: typo.
........
r76559 | georg.brandl | 2009-11-28 12:11:50 +0100 (Sa, 28 Nov 2009) | 1 line
Fix versions and spacing.
........
r76882 | georg.brandl | 2009-12-19 18:30:28 +0100 (Sa, 19 Dez 2009) | 1 line
#7527: use standard versionadded tags.
........
r76883 | georg.brandl | 2009-12-19 18:34:32 +0100 (Sa, 19 Dez 2009) | 1 line
#7521: remove Py_GetBuildNumber(), which was removed in favor of Py_GetBuildInfo().
........
r76886 | georg.brandl | 2009-12-19 18:43:33 +0100 (Sa, 19 Dez 2009) | 1 line
#7493: review of Design FAQ by Florent Xicluna.
........
r76891 | georg.brandl | 2009-12-19 19:16:31 +0100 (Sa, 19 Dez 2009) | 1 line
#7479: add note about function availability on Unices.
........
r76892 | georg.brandl | 2009-12-19 19:20:18 +0100 (Sa, 19 Dez 2009) | 1 line
#7480: remove tautology.
........
r76920 | georg.brandl | 2009-12-20 15:20:16 +0100 (So, 20 Dez 2009) | 1 line
#7495: backport Programming FAQ review to trunk.
........
r76924 | georg.brandl | 2009-12-20 15:28:05 +0100 (So, 20 Dez 2009) | 1 line
Small indentation fix.
........
r76925 | georg.brandl | 2009-12-20 15:33:20 +0100 (So, 20 Dez 2009) | 1 line
#7381: subprocess documentation and library docstring consistency fixes.
........
r77081 | georg.brandl | 2009-12-28 08:59:05 +0100 (Mo, 28 Dez 2009) | 1 line
#7577: fix signature of PyBuffer_FillInfo().
........
r77084 | georg.brandl | 2009-12-28 09:01:59 +0100 (Mo, 28 Dez 2009) | 1 line
#7586: fix typo.
........
r77086 | georg.brandl | 2009-12-28 09:09:32 +0100 (Mo, 28 Dez 2009) | 1 line
#7381: consistency update, and backport avoiding ``None >= 0`` check from py3k.
........
r77092 | georg.brandl | 2009-12-28 09:48:24 +0100 (Mo, 28 Dez 2009) | 1 line
#7404: remove reference to non-existing example files.
........
2010-03-21 16:06:51 -03:00
|
|
|
This feature is only available if Python is built with universal newline
|
|
|
|
support (the default). Also, the newlines attribute of the file objects
|
|
|
|
:attr:`stdout`, :attr:`stdin` and :attr:`stderr` are not updated by the
|
|
|
|
communicate() method.
|
2007-08-15 11:28:01 -03:00
|
|
|
|
|
|
|
The *startupinfo* and *creationflags*, if given, will be passed to the
|
|
|
|
underlying CreateProcess() function. They can specify things such as appearance
|
|
|
|
of the main window and priority for the new process. (Windows only)
|
|
|
|
|
|
|
|
|
Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r67571 | georg.brandl | 2008-12-05 10:13:45 +0100 (Fri, 05 Dec 2008) | 2 lines
Use markup.
........
r67574 | georg.brandl | 2008-12-05 10:25:32 +0100 (Fri, 05 Dec 2008) | 2 lines
#4441 followup: Add link to open() docs for Windows.
........
r67575 | georg.brandl | 2008-12-05 12:34:51 +0100 (Fri, 05 Dec 2008) | 2 lines
#4544: add `dedent` to textwrap.__all__.
........
r67576 | georg.brandl | 2008-12-05 13:09:41 +0100 (Fri, 05 Dec 2008) | 2 lines
#4529: fix parser's validation for try-except-finally statements.
........
r67579 | georg.brandl | 2008-12-05 16:29:39 +0100 (Fri, 05 Dec 2008) | 2 lines
#4517: add "special method" glossary entry and clarify when __getattribute__ is bypassed.
........
r67580 | georg.brandl | 2008-12-05 16:32:29 +0100 (Fri, 05 Dec 2008) | 2 lines
#4478: document that copyfile() can raise Error.
........
r67581 | georg.brandl | 2008-12-05 16:42:03 +0100 (Fri, 05 Dec 2008) | 2 lines
#3171: document that *slice are removed in 3k.
........
r67583 | georg.brandl | 2008-12-05 16:52:20 +0100 (Fri, 05 Dec 2008) | 4 lines
Move __import__ to the bottom of the functions list.
It doesn't make sense for such a fundamental document to have
the most obscure function listed at the top.
........
r67591 | georg.brandl | 2008-12-05 19:00:06 +0100 (Fri, 05 Dec 2008) | 2 lines
Followup to #4511: add link from decorator glossary entry to definition.
........
r67597 | georg.brandl | 2008-12-05 20:03:19 +0100 (Fri, 05 Dec 2008) | 2 lines
Remove confusing sentence part.
........
r67608 | georg.brandl | 2008-12-06 12:57:12 +0100 (Sat, 06 Dec 2008) | 2 lines
Follow-up to #4488: document PIPE and STDOUT properly.
........
r67631 | georg.brandl | 2008-12-07 12:54:07 +0100 (Sun, 07 Dec 2008) | 2 lines
Add link to the favicon to the docs.
........
2008-12-07 10:47:12 -04:00
|
|
|
.. data:: PIPE
|
|
|
|
|
|
|
|
Special value that can be used as the *stdin*, *stdout* or *stderr* argument
|
|
|
|
to :class:`Popen` and indicates that a pipe to the standard stream should be
|
|
|
|
opened.
|
|
|
|
|
|
|
|
|
|
|
|
.. data:: STDOUT
|
|
|
|
|
|
|
|
Special value that can be used as the *stderr* argument to :class:`Popen` and
|
|
|
|
indicates that standard error should go into the same handle as standard
|
|
|
|
output.
|
Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r68133 | antoine.pitrou | 2009-01-01 16:38:03 +0100 (Thu, 01 Jan 2009) | 1 line
fill in actual issue number in tests
........
r68134 | hirokazu.yamamoto | 2009-01-01 16:45:39 +0100 (Thu, 01 Jan 2009) | 2 lines
Issue #4797: IOError.filename was not set when _fileio.FileIO failed to open
file with `str' filename on Windows.
........
r68141 | benjamin.peterson | 2009-01-01 17:43:12 +0100 (Thu, 01 Jan 2009) | 1 line
fix highlighting
........
r68142 | benjamin.peterson | 2009-01-01 18:29:49 +0100 (Thu, 01 Jan 2009) | 2 lines
welcome to 2009, Python!
........
r68145 | amaury.forgeotdarc | 2009-01-02 01:03:54 +0100 (Fri, 02 Jan 2009) | 5 lines
#4801 _collections module fails to build on cygwin.
_PyObject_GC_TRACK is the macro version of PyObject_GC_Track,
and according to documentation it should not be used for extension modules.
........
r68146 | ronald.oussoren | 2009-01-02 11:44:46 +0100 (Fri, 02 Jan 2009) | 2 lines
Fix for issue4472: "configure --enable-shared doesn't work on OSX"
........
r68148 | ronald.oussoren | 2009-01-02 11:48:31 +0100 (Fri, 02 Jan 2009) | 2 lines
Forgot to add a NEWS item in my previous checkin
........
r68149 | ronald.oussoren | 2009-01-02 11:50:48 +0100 (Fri, 02 Jan 2009) | 2 lines
Fix for issue4780
........
r68159 | ronald.oussoren | 2009-01-02 15:48:17 +0100 (Fri, 02 Jan 2009) | 2 lines
Fix for issue 1627952
........
r68160 | ronald.oussoren | 2009-01-02 15:52:09 +0100 (Fri, 02 Jan 2009) | 2 lines
Fix for issue r1737832
........
r68161 | ronald.oussoren | 2009-01-02 16:00:05 +0100 (Fri, 02 Jan 2009) | 3 lines
Fix for issue 1149804
........
r68162 | ronald.oussoren | 2009-01-02 16:06:00 +0100 (Fri, 02 Jan 2009) | 3 lines
Fix for issue 4472 is incompatible with Cygwin, this patch
should fix that.
........
r68166 | benjamin.peterson | 2009-01-02 19:26:23 +0100 (Fri, 02 Jan 2009) | 1 line
document PyMemberDef
........
r68171 | georg.brandl | 2009-01-02 21:25:14 +0100 (Fri, 02 Jan 2009) | 3 lines
#4811: fix markup glitches (mostly remains of the conversion),
found by Gabriel Genellina.
........
r68172 | martin.v.loewis | 2009-01-02 21:32:55 +0100 (Fri, 02 Jan 2009) | 2 lines
Issue #4075: Use OutputDebugStringW in Py_FatalError.
........
r68173 | martin.v.loewis | 2009-01-02 21:40:14 +0100 (Fri, 02 Jan 2009) | 2 lines
Issue #4051: Prevent conflict of UNICODE macros in cPickle.
........
r68174 | benjamin.peterson | 2009-01-02 21:47:27 +0100 (Fri, 02 Jan 2009) | 1 line
fix compilation on non-Windows platforms
........
r68179 | raymond.hettinger | 2009-01-02 22:26:45 +0100 (Fri, 02 Jan 2009) | 1 line
Issue #4615. Document how to use itertools for de-duping.
........
r68195 | georg.brandl | 2009-01-03 14:45:15 +0100 (Sat, 03 Jan 2009) | 2 lines
Remove useless string literal.
........
r68196 | georg.brandl | 2009-01-03 15:29:53 +0100 (Sat, 03 Jan 2009) | 2 lines
Fix indentation.
........
r68210 | georg.brandl | 2009-01-03 20:10:12 +0100 (Sat, 03 Jan 2009) | 2 lines
Set eol-style correctly for mp_distributing.py.
........
r68214 | georg.brandl | 2009-01-03 20:44:48 +0100 (Sat, 03 Jan 2009) | 2 lines
Make indentation consistent.
........
r68215 | georg.brandl | 2009-01-03 21:15:14 +0100 (Sat, 03 Jan 2009) | 2 lines
Fix role name.
........
r68217 | georg.brandl | 2009-01-03 21:30:15 +0100 (Sat, 03 Jan 2009) | 2 lines
Add rstlint, a little tool to find subtle markup problems and inconsistencies in the Doc sources.
........
r68218 | georg.brandl | 2009-01-03 21:38:59 +0100 (Sat, 03 Jan 2009) | 2 lines
Recognize usage of the default role.
........
r68219 | georg.brandl | 2009-01-03 21:47:01 +0100 (Sat, 03 Jan 2009) | 2 lines
Fix uses of the default role.
........
r68220 | georg.brandl | 2009-01-03 21:55:06 +0100 (Sat, 03 Jan 2009) | 2 lines
Remove trailing whitespace.
........
r68221 | georg.brandl | 2009-01-03 22:04:55 +0100 (Sat, 03 Jan 2009) | 2 lines
Remove tabs from the documentation.
........
r68222 | georg.brandl | 2009-01-03 22:11:58 +0100 (Sat, 03 Jan 2009) | 2 lines
Disable the line length checker by default.
........
2009-01-03 17:55:17 -04:00
|
|
|
|
Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r67571 | georg.brandl | 2008-12-05 10:13:45 +0100 (Fri, 05 Dec 2008) | 2 lines
Use markup.
........
r67574 | georg.brandl | 2008-12-05 10:25:32 +0100 (Fri, 05 Dec 2008) | 2 lines
#4441 followup: Add link to open() docs for Windows.
........
r67575 | georg.brandl | 2008-12-05 12:34:51 +0100 (Fri, 05 Dec 2008) | 2 lines
#4544: add `dedent` to textwrap.__all__.
........
r67576 | georg.brandl | 2008-12-05 13:09:41 +0100 (Fri, 05 Dec 2008) | 2 lines
#4529: fix parser's validation for try-except-finally statements.
........
r67579 | georg.brandl | 2008-12-05 16:29:39 +0100 (Fri, 05 Dec 2008) | 2 lines
#4517: add "special method" glossary entry and clarify when __getattribute__ is bypassed.
........
r67580 | georg.brandl | 2008-12-05 16:32:29 +0100 (Fri, 05 Dec 2008) | 2 lines
#4478: document that copyfile() can raise Error.
........
r67581 | georg.brandl | 2008-12-05 16:42:03 +0100 (Fri, 05 Dec 2008) | 2 lines
#3171: document that *slice are removed in 3k.
........
r67583 | georg.brandl | 2008-12-05 16:52:20 +0100 (Fri, 05 Dec 2008) | 4 lines
Move __import__ to the bottom of the functions list.
It doesn't make sense for such a fundamental document to have
the most obscure function listed at the top.
........
r67591 | georg.brandl | 2008-12-05 19:00:06 +0100 (Fri, 05 Dec 2008) | 2 lines
Followup to #4511: add link from decorator glossary entry to definition.
........
r67597 | georg.brandl | 2008-12-05 20:03:19 +0100 (Fri, 05 Dec 2008) | 2 lines
Remove confusing sentence part.
........
r67608 | georg.brandl | 2008-12-06 12:57:12 +0100 (Sat, 06 Dec 2008) | 2 lines
Follow-up to #4488: document PIPE and STDOUT properly.
........
r67631 | georg.brandl | 2008-12-07 12:54:07 +0100 (Sun, 07 Dec 2008) | 2 lines
Add link to the favicon to the docs.
........
2008-12-07 10:47:12 -04:00
|
|
|
|
2007-08-15 11:28:01 -03:00
|
|
|
Convenience Functions
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
This module also defines two shortcut functions:
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: call(*popenargs, **kwargs)
|
|
|
|
|
|
|
|
Run command with arguments. Wait for command to complete, then return the
|
|
|
|
:attr:`returncode` attribute.
|
|
|
|
|
2010-05-19 11:11:55 -03:00
|
|
|
The arguments are the same as for the :class:`Popen` constructor. Example::
|
2007-08-15 11:28:01 -03:00
|
|
|
|
Merged revisions 76538,76559,76882-76883,76886,76891-76892,76920,76924-76925,77081,77084,77086,77092 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r76538 | georg.brandl | 2009-11-26 21:48:25 +0100 (Do, 26 Nov 2009) | 1 line
#7400: typo.
........
r76559 | georg.brandl | 2009-11-28 12:11:50 +0100 (Sa, 28 Nov 2009) | 1 line
Fix versions and spacing.
........
r76882 | georg.brandl | 2009-12-19 18:30:28 +0100 (Sa, 19 Dez 2009) | 1 line
#7527: use standard versionadded tags.
........
r76883 | georg.brandl | 2009-12-19 18:34:32 +0100 (Sa, 19 Dez 2009) | 1 line
#7521: remove Py_GetBuildNumber(), which was removed in favor of Py_GetBuildInfo().
........
r76886 | georg.brandl | 2009-12-19 18:43:33 +0100 (Sa, 19 Dez 2009) | 1 line
#7493: review of Design FAQ by Florent Xicluna.
........
r76891 | georg.brandl | 2009-12-19 19:16:31 +0100 (Sa, 19 Dez 2009) | 1 line
#7479: add note about function availability on Unices.
........
r76892 | georg.brandl | 2009-12-19 19:20:18 +0100 (Sa, 19 Dez 2009) | 1 line
#7480: remove tautology.
........
r76920 | georg.brandl | 2009-12-20 15:20:16 +0100 (So, 20 Dez 2009) | 1 line
#7495: backport Programming FAQ review to trunk.
........
r76924 | georg.brandl | 2009-12-20 15:28:05 +0100 (So, 20 Dez 2009) | 1 line
Small indentation fix.
........
r76925 | georg.brandl | 2009-12-20 15:33:20 +0100 (So, 20 Dez 2009) | 1 line
#7381: subprocess documentation and library docstring consistency fixes.
........
r77081 | georg.brandl | 2009-12-28 08:59:05 +0100 (Mo, 28 Dez 2009) | 1 line
#7577: fix signature of PyBuffer_FillInfo().
........
r77084 | georg.brandl | 2009-12-28 09:01:59 +0100 (Mo, 28 Dez 2009) | 1 line
#7586: fix typo.
........
r77086 | georg.brandl | 2009-12-28 09:09:32 +0100 (Mo, 28 Dez 2009) | 1 line
#7381: consistency update, and backport avoiding ``None >= 0`` check from py3k.
........
r77092 | georg.brandl | 2009-12-28 09:48:24 +0100 (Mo, 28 Dez 2009) | 1 line
#7404: remove reference to non-existing example files.
........
2010-03-21 16:06:51 -03:00
|
|
|
>>> retcode = subprocess.call(["ls", "-l"])
|
2007-08-15 11:28:01 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. function:: check_call(*popenargs, **kwargs)
|
|
|
|
|
|
|
|
Run command with arguments. Wait for command to complete. If the exit code was
|
2008-09-30 10:01:46 -03:00
|
|
|
zero then return, otherwise raise :exc:`CalledProcessError`. The
|
2007-08-15 11:28:01 -03:00
|
|
|
:exc:`CalledProcessError` object will have the return code in the
|
|
|
|
:attr:`returncode` attribute.
|
|
|
|
|
2010-05-19 11:11:55 -03:00
|
|
|
The arguments are the same as for the :class:`Popen` constructor. Example::
|
2007-08-15 11:28:01 -03:00
|
|
|
|
Merged revisions 76538,76559,76882-76883,76886,76891-76892,76920,76924-76925,77081,77084,77086,77092 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r76538 | georg.brandl | 2009-11-26 21:48:25 +0100 (Do, 26 Nov 2009) | 1 line
#7400: typo.
........
r76559 | georg.brandl | 2009-11-28 12:11:50 +0100 (Sa, 28 Nov 2009) | 1 line
Fix versions and spacing.
........
r76882 | georg.brandl | 2009-12-19 18:30:28 +0100 (Sa, 19 Dez 2009) | 1 line
#7527: use standard versionadded tags.
........
r76883 | georg.brandl | 2009-12-19 18:34:32 +0100 (Sa, 19 Dez 2009) | 1 line
#7521: remove Py_GetBuildNumber(), which was removed in favor of Py_GetBuildInfo().
........
r76886 | georg.brandl | 2009-12-19 18:43:33 +0100 (Sa, 19 Dez 2009) | 1 line
#7493: review of Design FAQ by Florent Xicluna.
........
r76891 | georg.brandl | 2009-12-19 19:16:31 +0100 (Sa, 19 Dez 2009) | 1 line
#7479: add note about function availability on Unices.
........
r76892 | georg.brandl | 2009-12-19 19:20:18 +0100 (Sa, 19 Dez 2009) | 1 line
#7480: remove tautology.
........
r76920 | georg.brandl | 2009-12-20 15:20:16 +0100 (So, 20 Dez 2009) | 1 line
#7495: backport Programming FAQ review to trunk.
........
r76924 | georg.brandl | 2009-12-20 15:28:05 +0100 (So, 20 Dez 2009) | 1 line
Small indentation fix.
........
r76925 | georg.brandl | 2009-12-20 15:33:20 +0100 (So, 20 Dez 2009) | 1 line
#7381: subprocess documentation and library docstring consistency fixes.
........
r77081 | georg.brandl | 2009-12-28 08:59:05 +0100 (Mo, 28 Dez 2009) | 1 line
#7577: fix signature of PyBuffer_FillInfo().
........
r77084 | georg.brandl | 2009-12-28 09:01:59 +0100 (Mo, 28 Dez 2009) | 1 line
#7586: fix typo.
........
r77086 | georg.brandl | 2009-12-28 09:09:32 +0100 (Mo, 28 Dez 2009) | 1 line
#7381: consistency update, and backport avoiding ``None >= 0`` check from py3k.
........
r77092 | georg.brandl | 2009-12-28 09:48:24 +0100 (Mo, 28 Dez 2009) | 1 line
#7404: remove reference to non-existing example files.
........
2010-03-21 16:06:51 -03:00
|
|
|
>>> subprocess.check_call(["ls", "-l"])
|
|
|
|
0
|
2007-08-15 11:28:01 -03:00
|
|
|
|
|
|
|
.. versionadded:: 2.5
|
|
|
|
|
|
|
|
|
|
|
|
Exceptions
|
|
|
|
^^^^^^^^^^
|
|
|
|
|
|
|
|
Exceptions raised in the child process, before the new program has started to
|
|
|
|
execute, will be re-raised in the parent. Additionally, the exception object
|
|
|
|
will have one extra attribute called :attr:`child_traceback`, which is a string
|
|
|
|
containing traceback information from the childs point of view.
|
|
|
|
|
|
|
|
The most common exception raised is :exc:`OSError`. This occurs, for example,
|
|
|
|
when trying to execute a non-existent file. Applications should prepare for
|
|
|
|
:exc:`OSError` exceptions.
|
|
|
|
|
|
|
|
A :exc:`ValueError` will be raised if :class:`Popen` is called with invalid
|
|
|
|
arguments.
|
|
|
|
|
|
|
|
check_call() will raise :exc:`CalledProcessError`, if the called process returns
|
|
|
|
a non-zero return code.
|
|
|
|
|
|
|
|
|
|
|
|
Security
|
|
|
|
^^^^^^^^
|
|
|
|
|
|
|
|
Unlike some other popen functions, this implementation will never call /bin/sh
|
|
|
|
implicitly. This means that all characters, including shell metacharacters, can
|
|
|
|
safely be passed to child processes.
|
|
|
|
|
|
|
|
|
|
|
|
Popen Objects
|
|
|
|
-------------
|
|
|
|
|
|
|
|
Instances of the :class:`Popen` class have the following methods:
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: Popen.poll()
|
|
|
|
|
2008-01-06 12:01:26 -04:00
|
|
|
Check if child process has terminated. Set and return :attr:`returncode`
|
|
|
|
attribute.
|
2007-08-15 11:28:01 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. method:: Popen.wait()
|
|
|
|
|
2008-01-06 12:01:26 -04:00
|
|
|
Wait for child process to terminate. Set and return :attr:`returncode`
|
|
|
|
attribute.
|
2007-08-15 11:28:01 -03:00
|
|
|
|
2008-08-04 03:29:36 -03:00
|
|
|
.. warning::
|
|
|
|
|
|
|
|
This will deadlock if the child process generates enough output to a
|
2008-08-04 15:34:07 -03:00
|
|
|
stdout or stderr pipe such that it blocks waiting for the OS pipe buffer
|
|
|
|
to accept more data. Use :meth:`communicate` to avoid that.
|
2008-08-03 22:03:50 -03:00
|
|
|
|
2007-08-15 11:28:01 -03:00
|
|
|
|
|
|
|
.. method:: Popen.communicate(input=None)
|
|
|
|
|
|
|
|
Interact with process: Send data to stdin. Read data from stdout and stderr,
|
|
|
|
until end-of-file is reached. Wait for process to terminate. The optional
|
|
|
|
*input* argument should be a string to be sent to the child process, or
|
|
|
|
``None``, if no data should be sent to the child.
|
|
|
|
|
Merged revisions 67326,67498,67531-67532,67538,67553-67554,67556-67557 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r67326 | benjamin.peterson | 2008-11-22 02:59:15 +0100 (Sat, 22 Nov 2008) | 1 line
backport r67325: make FileIO.mode always contain 'b'
........
r67498 | raymond.hettinger | 2008-12-03 16:42:10 +0100 (Wed, 03 Dec 2008) | 1 line
Backport r67478
........
r67531 | georg.brandl | 2008-12-04 19:54:05 +0100 (Thu, 04 Dec 2008) | 2 lines
Add reference to enumerate() to indices example.
........
r67532 | georg.brandl | 2008-12-04 19:59:16 +0100 (Thu, 04 Dec 2008) | 2 lines
Add another heapq example.
........
r67538 | georg.brandl | 2008-12-04 22:28:16 +0100 (Thu, 04 Dec 2008) | 2 lines
Clarification to avoid confusing output with file descriptors.
........
r67553 | georg.brandl | 2008-12-05 08:49:49 +0100 (Fri, 05 Dec 2008) | 2 lines
#4408: document regex.groups.
........
r67554 | georg.brandl | 2008-12-05 08:52:26 +0100 (Fri, 05 Dec 2008) | 2 lines
#4409: fix asterisks looking like footnotes.
........
r67556 | georg.brandl | 2008-12-05 09:02:17 +0100 (Fri, 05 Dec 2008) | 2 lines
#4441: improve doc for os.open() flags.
........
r67557 | georg.brandl | 2008-12-05 09:06:57 +0100 (Fri, 05 Dec 2008) | 2 lines
Add an index entry for "subclassing immutable types".
........
2008-12-05 05:08:28 -04:00
|
|
|
:meth:`communicate` returns a tuple ``(stdoutdata, stderrdata)``.
|
2007-08-15 11:28:01 -03:00
|
|
|
|
2007-11-24 07:31:46 -04:00
|
|
|
Note that if you want to send data to the process's stdin, you need to create
|
|
|
|
the Popen object with ``stdin=PIPE``. Similarly, to get anything other than
|
|
|
|
``None`` in the result tuple, you need to give ``stdout=PIPE`` and/or
|
|
|
|
``stderr=PIPE`` too.
|
|
|
|
|
2008-01-06 12:01:26 -04:00
|
|
|
.. note::
|
2007-08-15 11:28:01 -03:00
|
|
|
|
2008-01-06 12:01:26 -04:00
|
|
|
The data read is buffered in memory, so do not use this method if the data
|
|
|
|
size is large or unlimited.
|
2007-08-15 11:28:01 -03:00
|
|
|
|
|
|
|
|
2008-04-18 23:23:57 -03:00
|
|
|
.. method:: Popen.send_signal(signal)
|
|
|
|
|
|
|
|
Sends the signal *signal* to the child.
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
On Windows only SIGTERM is supported so far. It's an alias for
|
2008-04-19 05:23:59 -03:00
|
|
|
:meth:`terminate`.
|
|
|
|
|
|
|
|
.. versionadded:: 2.6
|
2008-04-18 23:23:57 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. method:: Popen.terminate()
|
|
|
|
|
|
|
|
Stop the child. On Posix OSs the method sends SIGTERM to the
|
2008-04-20 23:08:00 -03:00
|
|
|
child. On Windows the Win32 API function :cfunc:`TerminateProcess` is called
|
2008-04-18 23:23:57 -03:00
|
|
|
to stop the child.
|
|
|
|
|
2008-04-19 05:23:59 -03:00
|
|
|
.. versionadded:: 2.6
|
|
|
|
|
2008-04-18 23:23:57 -03:00
|
|
|
|
|
|
|
.. method:: Popen.kill()
|
|
|
|
|
|
|
|
Kills the child. On Posix OSs the function sends SIGKILL to the child.
|
2008-04-19 05:23:59 -03:00
|
|
|
On Windows :meth:`kill` is an alias for :meth:`terminate`.
|
|
|
|
|
|
|
|
.. versionadded:: 2.6
|
2008-04-18 23:23:57 -03:00
|
|
|
|
|
|
|
|
2008-01-06 12:01:26 -04:00
|
|
|
The following attributes are also available:
|
2007-08-15 11:28:01 -03:00
|
|
|
|
2008-08-04 03:29:36 -03:00
|
|
|
.. warning::
|
|
|
|
|
Merged revisions 72007-72010,72036-72037 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r72007 | georg.brandl | 2009-04-27 17:09:25 +0200 (Mo, 27 Apr 2009) | 1 line
#5856: fix typo s in traceback example.
........
r72008 | georg.brandl | 2009-04-27 17:10:44 +0200 (Mo, 27 Apr 2009) | 1 line
Remove ".. warning::" markup that doesnt contain warnings for users, rather todo items.
........
r72009 | georg.brandl | 2009-04-27 17:29:09 +0200 (Mo, 27 Apr 2009) | 3 lines
Demote warnings to notices where appropriate, following the goal that as few "red box" warnings
should clutter the docs as possible. Part 1: stuff that gets merged to Py3k.
........
r72010 | georg.brandl | 2009-04-27 17:29:26 +0200 (Mo, 27 Apr 2009) | 2 lines
Demote warnings to notices, part 2: stuff that is 2.x-only.
........
r72036 | georg.brandl | 2009-04-27 19:04:23 +0200 (Mo, 27 Apr 2009) | 1 line
#5848: small unittest doc patch.
........
r72037 | georg.brandl | 2009-04-27 19:09:53 +0200 (Mo, 27 Apr 2009) | 1 line
#5840: dont claim we dont support TLS.
........
2009-04-28 15:23:28 -03:00
|
|
|
Use :meth:`communicate` rather than :attr:`.stdin.write <stdin>`,
|
|
|
|
:attr:`.stdout.read <stdout>` or :attr:`.stderr.read <stderr>` to avoid
|
|
|
|
deadlocks due to any of the other OS pipe buffers filling up and blocking the
|
|
|
|
child process.
|
2008-08-04 03:29:36 -03:00
|
|
|
|
|
|
|
|
2007-08-15 11:28:01 -03:00
|
|
|
.. attribute:: Popen.stdin
|
|
|
|
|
Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r67571 | georg.brandl | 2008-12-05 10:13:45 +0100 (Fri, 05 Dec 2008) | 2 lines
Use markup.
........
r67574 | georg.brandl | 2008-12-05 10:25:32 +0100 (Fri, 05 Dec 2008) | 2 lines
#4441 followup: Add link to open() docs for Windows.
........
r67575 | georg.brandl | 2008-12-05 12:34:51 +0100 (Fri, 05 Dec 2008) | 2 lines
#4544: add `dedent` to textwrap.__all__.
........
r67576 | georg.brandl | 2008-12-05 13:09:41 +0100 (Fri, 05 Dec 2008) | 2 lines
#4529: fix parser's validation for try-except-finally statements.
........
r67579 | georg.brandl | 2008-12-05 16:29:39 +0100 (Fri, 05 Dec 2008) | 2 lines
#4517: add "special method" glossary entry and clarify when __getattribute__ is bypassed.
........
r67580 | georg.brandl | 2008-12-05 16:32:29 +0100 (Fri, 05 Dec 2008) | 2 lines
#4478: document that copyfile() can raise Error.
........
r67581 | georg.brandl | 2008-12-05 16:42:03 +0100 (Fri, 05 Dec 2008) | 2 lines
#3171: document that *slice are removed in 3k.
........
r67583 | georg.brandl | 2008-12-05 16:52:20 +0100 (Fri, 05 Dec 2008) | 4 lines
Move __import__ to the bottom of the functions list.
It doesn't make sense for such a fundamental document to have
the most obscure function listed at the top.
........
r67591 | georg.brandl | 2008-12-05 19:00:06 +0100 (Fri, 05 Dec 2008) | 2 lines
Followup to #4511: add link from decorator glossary entry to definition.
........
r67597 | georg.brandl | 2008-12-05 20:03:19 +0100 (Fri, 05 Dec 2008) | 2 lines
Remove confusing sentence part.
........
r67608 | georg.brandl | 2008-12-06 12:57:12 +0100 (Sat, 06 Dec 2008) | 2 lines
Follow-up to #4488: document PIPE and STDOUT properly.
........
r67631 | georg.brandl | 2008-12-07 12:54:07 +0100 (Sun, 07 Dec 2008) | 2 lines
Add link to the favicon to the docs.
........
2008-12-07 10:47:12 -04:00
|
|
|
If the *stdin* argument was :data:`PIPE`, this attribute is a file object
|
|
|
|
that provides input to the child process. Otherwise, it is ``None``.
|
2007-08-15 11:28:01 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: Popen.stdout
|
|
|
|
|
Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r67571 | georg.brandl | 2008-12-05 10:13:45 +0100 (Fri, 05 Dec 2008) | 2 lines
Use markup.
........
r67574 | georg.brandl | 2008-12-05 10:25:32 +0100 (Fri, 05 Dec 2008) | 2 lines
#4441 followup: Add link to open() docs for Windows.
........
r67575 | georg.brandl | 2008-12-05 12:34:51 +0100 (Fri, 05 Dec 2008) | 2 lines
#4544: add `dedent` to textwrap.__all__.
........
r67576 | georg.brandl | 2008-12-05 13:09:41 +0100 (Fri, 05 Dec 2008) | 2 lines
#4529: fix parser's validation for try-except-finally statements.
........
r67579 | georg.brandl | 2008-12-05 16:29:39 +0100 (Fri, 05 Dec 2008) | 2 lines
#4517: add "special method" glossary entry and clarify when __getattribute__ is bypassed.
........
r67580 | georg.brandl | 2008-12-05 16:32:29 +0100 (Fri, 05 Dec 2008) | 2 lines
#4478: document that copyfile() can raise Error.
........
r67581 | georg.brandl | 2008-12-05 16:42:03 +0100 (Fri, 05 Dec 2008) | 2 lines
#3171: document that *slice are removed in 3k.
........
r67583 | georg.brandl | 2008-12-05 16:52:20 +0100 (Fri, 05 Dec 2008) | 4 lines
Move __import__ to the bottom of the functions list.
It doesn't make sense for such a fundamental document to have
the most obscure function listed at the top.
........
r67591 | georg.brandl | 2008-12-05 19:00:06 +0100 (Fri, 05 Dec 2008) | 2 lines
Followup to #4511: add link from decorator glossary entry to definition.
........
r67597 | georg.brandl | 2008-12-05 20:03:19 +0100 (Fri, 05 Dec 2008) | 2 lines
Remove confusing sentence part.
........
r67608 | georg.brandl | 2008-12-06 12:57:12 +0100 (Sat, 06 Dec 2008) | 2 lines
Follow-up to #4488: document PIPE and STDOUT properly.
........
r67631 | georg.brandl | 2008-12-07 12:54:07 +0100 (Sun, 07 Dec 2008) | 2 lines
Add link to the favicon to the docs.
........
2008-12-07 10:47:12 -04:00
|
|
|
If the *stdout* argument was :data:`PIPE`, this attribute is a file object
|
|
|
|
that provides output from the child process. Otherwise, it is ``None``.
|
2007-08-15 11:28:01 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: Popen.stderr
|
|
|
|
|
Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r67571 | georg.brandl | 2008-12-05 10:13:45 +0100 (Fri, 05 Dec 2008) | 2 lines
Use markup.
........
r67574 | georg.brandl | 2008-12-05 10:25:32 +0100 (Fri, 05 Dec 2008) | 2 lines
#4441 followup: Add link to open() docs for Windows.
........
r67575 | georg.brandl | 2008-12-05 12:34:51 +0100 (Fri, 05 Dec 2008) | 2 lines
#4544: add `dedent` to textwrap.__all__.
........
r67576 | georg.brandl | 2008-12-05 13:09:41 +0100 (Fri, 05 Dec 2008) | 2 lines
#4529: fix parser's validation for try-except-finally statements.
........
r67579 | georg.brandl | 2008-12-05 16:29:39 +0100 (Fri, 05 Dec 2008) | 2 lines
#4517: add "special method" glossary entry and clarify when __getattribute__ is bypassed.
........
r67580 | georg.brandl | 2008-12-05 16:32:29 +0100 (Fri, 05 Dec 2008) | 2 lines
#4478: document that copyfile() can raise Error.
........
r67581 | georg.brandl | 2008-12-05 16:42:03 +0100 (Fri, 05 Dec 2008) | 2 lines
#3171: document that *slice are removed in 3k.
........
r67583 | georg.brandl | 2008-12-05 16:52:20 +0100 (Fri, 05 Dec 2008) | 4 lines
Move __import__ to the bottom of the functions list.
It doesn't make sense for such a fundamental document to have
the most obscure function listed at the top.
........
r67591 | georg.brandl | 2008-12-05 19:00:06 +0100 (Fri, 05 Dec 2008) | 2 lines
Followup to #4511: add link from decorator glossary entry to definition.
........
r67597 | georg.brandl | 2008-12-05 20:03:19 +0100 (Fri, 05 Dec 2008) | 2 lines
Remove confusing sentence part.
........
r67608 | georg.brandl | 2008-12-06 12:57:12 +0100 (Sat, 06 Dec 2008) | 2 lines
Follow-up to #4488: document PIPE and STDOUT properly.
........
r67631 | georg.brandl | 2008-12-07 12:54:07 +0100 (Sun, 07 Dec 2008) | 2 lines
Add link to the favicon to the docs.
........
2008-12-07 10:47:12 -04:00
|
|
|
If the *stderr* argument was :data:`PIPE`, this attribute is a file object
|
|
|
|
that provides error output from the child process. Otherwise, it is
|
|
|
|
``None``.
|
2007-08-15 11:28:01 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: Popen.pid
|
|
|
|
|
|
|
|
The process ID of the child process.
|
|
|
|
|
Merged revisions 78859-78860,78952,79168-79169,79173,79176,79178-79179,79181,79184-79185,79192,79212 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r78859 | georg.brandl | 2010-03-12 10:57:43 +0100 (Fr, 12 Mär 2010) | 1 line
Get rid of backticks.
........
r78860 | georg.brandl | 2010-03-12 11:02:03 +0100 (Fr, 12 Mär 2010) | 1 line
Fix warnings from "make check".
........
r78952 | georg.brandl | 2010-03-14 10:55:08 +0100 (So, 14 Mär 2010) | 1 line
#8137: add iso-8859-16 to the standard encodings table.
........
r79168 | georg.brandl | 2010-03-21 10:01:27 +0100 (So, 21 Mär 2010) | 1 line
Fix some issues found by Jacques Ducasse on the docs list.
........
r79169 | georg.brandl | 2010-03-21 10:02:01 +0100 (So, 21 Mär 2010) | 1 line
Remove the "built-in objects" file. It only contained two paragraphs of which only one contained useful information, which belongs in the ref manual however.
........
r79173 | georg.brandl | 2010-03-21 10:09:38 +0100 (So, 21 Mär 2010) | 1 line
Document that GzipFile supports iteration.
........
r79176 | georg.brandl | 2010-03-21 10:17:41 +0100 (So, 21 Mär 2010) | 1 line
Introduce copy by slicing, used in later chapters.
........
r79178 | georg.brandl | 2010-03-21 10:28:16 +0100 (So, 21 Mär 2010) | 1 line
Clarify that for shell=True, the shell PID will be the child PID.
........
r79179 | georg.brandl | 2010-03-21 10:37:54 +0100 (So, 21 Mär 2010) | 1 line
Mention inefficiency of lists as queues, add link to collections.deque discussion.
........
r79181 | georg.brandl | 2010-03-21 10:51:16 +0100 (So, 21 Mär 2010) | 1 line
Update os.kill() emulation example for Windows to use ctypes.
........
r79184 | georg.brandl | 2010-03-21 10:58:36 +0100 (So, 21 Mär 2010) | 1 line
Update text for newest US DST regulation. The sample file already has the calculation right.
........
r79185 | georg.brandl | 2010-03-21 11:02:47 +0100 (So, 21 Mär 2010) | 1 line
Include structmember.h correctly.
........
r79192 | georg.brandl | 2010-03-21 12:50:58 +0100 (So, 21 Mär 2010) | 1 line
Remove leftover word.
........
r79212 | georg.brandl | 2010-03-21 20:01:38 +0100 (So, 21 Mär 2010) | 1 line
Fix plural.
........
2010-03-21 16:34:26 -03:00
|
|
|
Note that if you set the *shell* argument to ``True``, this is the process ID
|
|
|
|
of the spawned shell.
|
|
|
|
|
2007-08-15 11:28:01 -03:00
|
|
|
|
|
|
|
.. attribute:: Popen.returncode
|
|
|
|
|
2008-01-06 12:01:26 -04:00
|
|
|
The child return code, set by :meth:`poll` and :meth:`wait` (and indirectly
|
|
|
|
by :meth:`communicate`). A ``None`` value indicates that the process
|
|
|
|
hasn't terminated yet.
|
Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r68133 | antoine.pitrou | 2009-01-01 16:38:03 +0100 (Thu, 01 Jan 2009) | 1 line
fill in actual issue number in tests
........
r68134 | hirokazu.yamamoto | 2009-01-01 16:45:39 +0100 (Thu, 01 Jan 2009) | 2 lines
Issue #4797: IOError.filename was not set when _fileio.FileIO failed to open
file with `str' filename on Windows.
........
r68141 | benjamin.peterson | 2009-01-01 17:43:12 +0100 (Thu, 01 Jan 2009) | 1 line
fix highlighting
........
r68142 | benjamin.peterson | 2009-01-01 18:29:49 +0100 (Thu, 01 Jan 2009) | 2 lines
welcome to 2009, Python!
........
r68145 | amaury.forgeotdarc | 2009-01-02 01:03:54 +0100 (Fri, 02 Jan 2009) | 5 lines
#4801 _collections module fails to build on cygwin.
_PyObject_GC_TRACK is the macro version of PyObject_GC_Track,
and according to documentation it should not be used for extension modules.
........
r68146 | ronald.oussoren | 2009-01-02 11:44:46 +0100 (Fri, 02 Jan 2009) | 2 lines
Fix for issue4472: "configure --enable-shared doesn't work on OSX"
........
r68148 | ronald.oussoren | 2009-01-02 11:48:31 +0100 (Fri, 02 Jan 2009) | 2 lines
Forgot to add a NEWS item in my previous checkin
........
r68149 | ronald.oussoren | 2009-01-02 11:50:48 +0100 (Fri, 02 Jan 2009) | 2 lines
Fix for issue4780
........
r68159 | ronald.oussoren | 2009-01-02 15:48:17 +0100 (Fri, 02 Jan 2009) | 2 lines
Fix for issue 1627952
........
r68160 | ronald.oussoren | 2009-01-02 15:52:09 +0100 (Fri, 02 Jan 2009) | 2 lines
Fix for issue r1737832
........
r68161 | ronald.oussoren | 2009-01-02 16:00:05 +0100 (Fri, 02 Jan 2009) | 3 lines
Fix for issue 1149804
........
r68162 | ronald.oussoren | 2009-01-02 16:06:00 +0100 (Fri, 02 Jan 2009) | 3 lines
Fix for issue 4472 is incompatible with Cygwin, this patch
should fix that.
........
r68166 | benjamin.peterson | 2009-01-02 19:26:23 +0100 (Fri, 02 Jan 2009) | 1 line
document PyMemberDef
........
r68171 | georg.brandl | 2009-01-02 21:25:14 +0100 (Fri, 02 Jan 2009) | 3 lines
#4811: fix markup glitches (mostly remains of the conversion),
found by Gabriel Genellina.
........
r68172 | martin.v.loewis | 2009-01-02 21:32:55 +0100 (Fri, 02 Jan 2009) | 2 lines
Issue #4075: Use OutputDebugStringW in Py_FatalError.
........
r68173 | martin.v.loewis | 2009-01-02 21:40:14 +0100 (Fri, 02 Jan 2009) | 2 lines
Issue #4051: Prevent conflict of UNICODE macros in cPickle.
........
r68174 | benjamin.peterson | 2009-01-02 21:47:27 +0100 (Fri, 02 Jan 2009) | 1 line
fix compilation on non-Windows platforms
........
r68179 | raymond.hettinger | 2009-01-02 22:26:45 +0100 (Fri, 02 Jan 2009) | 1 line
Issue #4615. Document how to use itertools for de-duping.
........
r68195 | georg.brandl | 2009-01-03 14:45:15 +0100 (Sat, 03 Jan 2009) | 2 lines
Remove useless string literal.
........
r68196 | georg.brandl | 2009-01-03 15:29:53 +0100 (Sat, 03 Jan 2009) | 2 lines
Fix indentation.
........
r68210 | georg.brandl | 2009-01-03 20:10:12 +0100 (Sat, 03 Jan 2009) | 2 lines
Set eol-style correctly for mp_distributing.py.
........
r68214 | georg.brandl | 2009-01-03 20:44:48 +0100 (Sat, 03 Jan 2009) | 2 lines
Make indentation consistent.
........
r68215 | georg.brandl | 2009-01-03 21:15:14 +0100 (Sat, 03 Jan 2009) | 2 lines
Fix role name.
........
r68217 | georg.brandl | 2009-01-03 21:30:15 +0100 (Sat, 03 Jan 2009) | 2 lines
Add rstlint, a little tool to find subtle markup problems and inconsistencies in the Doc sources.
........
r68218 | georg.brandl | 2009-01-03 21:38:59 +0100 (Sat, 03 Jan 2009) | 2 lines
Recognize usage of the default role.
........
r68219 | georg.brandl | 2009-01-03 21:47:01 +0100 (Sat, 03 Jan 2009) | 2 lines
Fix uses of the default role.
........
r68220 | georg.brandl | 2009-01-03 21:55:06 +0100 (Sat, 03 Jan 2009) | 2 lines
Remove trailing whitespace.
........
r68221 | georg.brandl | 2009-01-03 22:04:55 +0100 (Sat, 03 Jan 2009) | 2 lines
Remove tabs from the documentation.
........
r68222 | georg.brandl | 2009-01-03 22:11:58 +0100 (Sat, 03 Jan 2009) | 2 lines
Disable the line length checker by default.
........
2009-01-03 17:55:17 -04:00
|
|
|
|
2008-01-06 12:01:26 -04:00
|
|
|
A negative value ``-N`` indicates that the child was terminated by signal
|
|
|
|
``N`` (Unix only).
|
2007-08-15 11:28:01 -03:00
|
|
|
|
|
|
|
|
2008-06-22 06:05:29 -03:00
|
|
|
.. _subprocess-replacements:
|
|
|
|
|
2007-08-15 11:28:01 -03:00
|
|
|
Replacing Older Functions with the subprocess Module
|
|
|
|
----------------------------------------------------
|
|
|
|
|
|
|
|
In this section, "a ==> b" means that b can be used as a replacement for a.
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
All functions in this section fail (more or less) silently if the executed
|
|
|
|
program cannot be found; this module raises an :exc:`OSError` exception.
|
|
|
|
|
|
|
|
In the following examples, we assume that the subprocess module is imported with
|
|
|
|
"from subprocess import \*".
|
|
|
|
|
|
|
|
|
|
|
|
Replacing /bin/sh shell backquote
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
::
|
|
|
|
|
|
|
|
output=`mycmd myarg`
|
|
|
|
==>
|
|
|
|
output = Popen(["mycmd", "myarg"], stdout=PIPE).communicate()[0]
|
|
|
|
|
|
|
|
|
Merged revisions 66801,66803-66804,66813,66854-66856,66866,66870-66872,66874,66887,66903,66905,66911,66913,66927,66932,66938,66942,66962,66964,66973-66974,66977,66992,66998-66999,67002,67005,67007,67028,67040-67041,67044,67070,67089,67091,67101,67117-67119,67123-67124 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r66801 | andrew.kuchling | 2008-10-04 23:51:59 +0200 (Sat, 04 Oct 2008) | 1 line
Punctuation fix; expand dict.update docstring to be clearer
................
r66803 | benjamin.peterson | 2008-10-05 00:15:31 +0200 (Sun, 05 Oct 2008) | 1 line
fix typo
................
r66804 | andrew.kuchling | 2008-10-05 02:11:56 +0200 (Sun, 05 Oct 2008) | 1 line
#1415508 from Rocky Bernstein: add docstrings for enable_interspersed_args(), disable_interspersed_args()
................
r66813 | andrew.kuchling | 2008-10-06 14:07:04 +0200 (Mon, 06 Oct 2008) | 3 lines
Per Greg Ward, optparse is no longer being externally maintained.
I'll look at the bugs in the Optik bug tracker and copy them to the Python bug
tracker if they're still relevant.
................
r66854 | georg.brandl | 2008-10-08 19:20:20 +0200 (Wed, 08 Oct 2008) | 2 lines
#4059: patch up some sqlite docs.
................
r66855 | georg.brandl | 2008-10-08 19:30:55 +0200 (Wed, 08 Oct 2008) | 2 lines
#4058: fix some whatsnew markup.
................
r66856 | georg.brandl | 2008-10-08 20:47:17 +0200 (Wed, 08 Oct 2008) | 3 lines
#3935: properly support list subclasses in the C impl. of bisect.
Patch reviewed by Raymond.
................
r66866 | benjamin.peterson | 2008-10-09 22:54:43 +0200 (Thu, 09 Oct 2008) | 1 line
update paragraph about __future__ for 2.6
................
r66870 | armin.rigo | 2008-10-10 10:40:44 +0200 (Fri, 10 Oct 2008) | 2 lines
Typo: "ThreadError" is the name in the C source.
................
r66871 | benjamin.peterson | 2008-10-10 22:38:49 +0200 (Fri, 10 Oct 2008) | 1 line
fix a small typo
................
r66872 | benjamin.peterson | 2008-10-10 22:51:37 +0200 (Fri, 10 Oct 2008) | 1 line
talk about how you can unzip with zip
................
r66874 | benjamin.peterson | 2008-10-11 00:23:41 +0200 (Sat, 11 Oct 2008) | 1 line
PyGILState_Acquire -> PyGILState_Ensure
................
r66887 | benjamin.peterson | 2008-10-13 23:51:40 +0200 (Mon, 13 Oct 2008) | 1 line
document how to disable fixers
................
r66903 | benjamin.peterson | 2008-10-15 22:34:09 +0200 (Wed, 15 Oct 2008) | 1 line
don't recurse into directories that start with '.'
................
r66905 | benjamin.peterson | 2008-10-15 23:05:55 +0200 (Wed, 15 Oct 2008) | 1 line
support the optional line argument for idle
................
r66911 | benjamin.peterson | 2008-10-16 01:10:28 +0200 (Thu, 16 Oct 2008) | 41 lines
Merged revisions 66805,66841,66860,66884-66886,66893,66907,66910 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r66805 | benjamin.peterson | 2008-10-04 20:11:02 -0500 (Sat, 04 Oct 2008) | 1 line
mention what the fixes directory is for
........
r66841 | benjamin.peterson | 2008-10-07 17:48:12 -0500 (Tue, 07 Oct 2008) | 1 line
use assertFalse and assertTrue
........
r66860 | benjamin.peterson | 2008-10-08 16:05:07 -0500 (Wed, 08 Oct 2008) | 1 line
instead of abusing the pattern matcher, use start_tree to find a next binding
........
r66884 | benjamin.peterson | 2008-10-13 15:50:30 -0500 (Mon, 13 Oct 2008) | 1 line
don't print tokens to stdout when -v is given
........
r66885 | benjamin.peterson | 2008-10-13 16:28:57 -0500 (Mon, 13 Oct 2008) | 1 line
add the -x option to disable fixers
........
r66886 | benjamin.peterson | 2008-10-13 16:33:53 -0500 (Mon, 13 Oct 2008) | 1 line
cut down on some crud
........
r66893 | benjamin.peterson | 2008-10-14 17:16:54 -0500 (Tue, 14 Oct 2008) | 1 line
add an optional set literal fixer
........
r66907 | benjamin.peterson | 2008-10-15 16:59:41 -0500 (Wed, 15 Oct 2008) | 1 line
don't write backup files by default
........
r66910 | benjamin.peterson | 2008-10-15 17:43:10 -0500 (Wed, 15 Oct 2008) | 1 line
add the -n option; it stops backupfiles from being written
........
................
r66913 | benjamin.peterson | 2008-10-16 20:52:14 +0200 (Thu, 16 Oct 2008) | 1 line
document that deque indexing is O(n) #4123
................
r66927 | andrew.kuchling | 2008-10-16 22:15:47 +0200 (Thu, 16 Oct 2008) | 1 line
Fix wording (2.6.1 backport candidate)
................
r66932 | benjamin.peterson | 2008-10-16 23:09:28 +0200 (Thu, 16 Oct 2008) | 1 line
check for error conditions in _json #3623
................
r66938 | benjamin.peterson | 2008-10-16 23:27:54 +0200 (Thu, 16 Oct 2008) | 1 line
fix possible ref leak
................
r66942 | benjamin.peterson | 2008-10-16 23:48:06 +0200 (Thu, 16 Oct 2008) | 1 line
fix more possible ref leaks in _json and use Py_CLEAR
................
r66962 | benjamin.peterson | 2008-10-17 22:01:01 +0200 (Fri, 17 Oct 2008) | 1 line
clarify CALL_FUNCTION #4141
................
r66964 | georg.brandl | 2008-10-17 23:41:49 +0200 (Fri, 17 Oct 2008) | 2 lines
Fix duplicate word.
................
r66973 | armin.ronacher | 2008-10-19 10:27:43 +0200 (Sun, 19 Oct 2008) | 3 lines
Fixed #4067 by implementing _attributes and _fields for the AST root node.
................
r66974 | benjamin.peterson | 2008-10-19 15:59:01 +0200 (Sun, 19 Oct 2008) | 1 line
fix compiler warning
................
r66977 | benjamin.peterson | 2008-10-19 21:39:16 +0200 (Sun, 19 Oct 2008) | 1 line
mention -n
................
r66992 | benjamin.peterson | 2008-10-21 22:51:13 +0200 (Tue, 21 Oct 2008) | 1 line
make sure to call iteritems()
................
r66998 | benjamin.peterson | 2008-10-22 22:57:43 +0200 (Wed, 22 Oct 2008) | 1 line
fix a few typos
................
r66999 | benjamin.peterson | 2008-10-22 23:05:30 +0200 (Wed, 22 Oct 2008) | 1 line
and another typo...
................
r67002 | hirokazu.yamamoto | 2008-10-23 02:37:33 +0200 (Thu, 23 Oct 2008) | 1 line
Issue #4183: Some tests didn't run with pickle.HIGHEST_PROTOCOL.
................
r67005 | walter.doerwald | 2008-10-23 15:11:39 +0200 (Thu, 23 Oct 2008) | 2 lines
Use the correct names of the stateless codec functions (Fixes issue 4178).
................
r67007 | benjamin.peterson | 2008-10-23 23:43:48 +0200 (Thu, 23 Oct 2008) | 1 line
only nonempty __slots__ don't work
................
r67028 | benjamin.peterson | 2008-10-26 01:27:07 +0200 (Sun, 26 Oct 2008) | 1 line
don't use a catch-all
................
r67040 | armin.rigo | 2008-10-28 18:01:21 +0100 (Tue, 28 Oct 2008) | 5 lines
Fix one of the tests: it relied on being present in an "output test" in
order to actually test what it was supposed to test, i.e. that the code
in the __del__ method did not crash. Use instead the new helper
test_support.captured_output().
................
r67041 | benjamin.peterson | 2008-10-29 21:33:00 +0100 (Wed, 29 Oct 2008) | 1 line
mention the version gettempdir() was added
................
r67044 | amaury.forgeotdarc | 2008-10-30 00:15:57 +0100 (Thu, 30 Oct 2008) | 3 lines
Correct error message in io.open():
closefd=True is the only accepted value with a file name.
................
r67070 | benjamin.peterson | 2008-10-31 21:41:44 +0100 (Fri, 31 Oct 2008) | 1 line
rephrase has_key doc
................
r67089 | benjamin.peterson | 2008-11-03 21:43:20 +0100 (Mon, 03 Nov 2008) | 1 line
clarify by splitting into multiple paragraphs
................
r67091 | benjamin.peterson | 2008-11-03 23:34:57 +0100 (Mon, 03 Nov 2008) | 1 line
move a FileIO test to test_fileio
................
r67101 | georg.brandl | 2008-11-04 21:49:35 +0100 (Tue, 04 Nov 2008) | 2 lines
#4167: fix markup glitches.
................
r67117 | georg.brandl | 2008-11-06 11:17:58 +0100 (Thu, 06 Nov 2008) | 2 lines
#4268: Use correct module for two toplevel functions.
................
r67118 | georg.brandl | 2008-11-06 11:19:11 +0100 (Thu, 06 Nov 2008) | 2 lines
#4267: small fixes in sqlite3 docs.
................
r67119 | georg.brandl | 2008-11-06 11:20:49 +0100 (Thu, 06 Nov 2008) | 2 lines
#4245: move Thread section to the top.
................
r67123 | georg.brandl | 2008-11-06 19:49:15 +0100 (Thu, 06 Nov 2008) | 2 lines
#4247: add "pass" examples to tutorial.
................
r67124 | andrew.kuchling | 2008-11-06 20:23:02 +0100 (Thu, 06 Nov 2008) | 1 line
Fix grammar error; reword two paragraphs
................
2008-11-07 04:56:27 -04:00
|
|
|
Replacing shell pipeline
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^
|
2007-08-15 11:28:01 -03:00
|
|
|
|
|
|
|
::
|
|
|
|
|
|
|
|
output=`dmesg | grep hda`
|
|
|
|
==>
|
|
|
|
p1 = Popen(["dmesg"], stdout=PIPE)
|
|
|
|
p2 = Popen(["grep", "hda"], stdin=p1.stdout, stdout=PIPE)
|
|
|
|
output = p2.communicate()[0]
|
|
|
|
|
|
|
|
|
2009-06-25 14:40:52 -03:00
|
|
|
Replacing :func:`os.system`
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
2007-08-15 11:28:01 -03:00
|
|
|
|
|
|
|
::
|
|
|
|
|
|
|
|
sts = os.system("mycmd" + " myarg")
|
|
|
|
==>
|
|
|
|
p = Popen("mycmd" + " myarg", shell=True)
|
Merged revisions 74008,74021-74022,74074-74075,74077,74148,74179,74188,74192-74194,74200,74205 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r74008 | benjamin.peterson | 2009-07-15 02:46:42 +0200 (Mi, 15 Jul 2009) | 1 line
update year
........
r74021 | georg.brandl | 2009-07-16 09:33:04 +0200 (Do, 16 Jul 2009) | 1 line
#6486: start with built in functions rather than "built in objects".
........
r74022 | georg.brandl | 2009-07-16 09:38:35 +0200 (Do, 16 Jul 2009) | 1 line
#6481: fix typo in os.system() replacement.
........
r74074 | georg.brandl | 2009-07-18 11:03:10 +0200 (Sa, 18 Jul 2009) | 1 line
#6513: fix example code: warning categories are classes, not instances.
........
r74075 | georg.brandl | 2009-07-18 11:06:31 +0200 (Sa, 18 Jul 2009) | 1 line
#6505: fix typos.
........
r74077 | georg.brandl | 2009-07-18 11:43:40 +0200 (Sa, 18 Jul 2009) | 1 line
#6489: fix an ambiguity in getiterator() documentation.
........
r74148 | ezio.melotti | 2009-07-21 22:18:27 +0200 (Di, 21 Jul 2009) | 1 line
#6536 fixed typo
........
r74179 | ezio.melotti | 2009-07-22 23:08:49 +0200 (Mi, 22 Jul 2009) | 1 line
#6423 has_key -> in
........
r74188 | benjamin.peterson | 2009-07-23 16:25:31 +0200 (Do, 23 Jul 2009) | 1 line
use bools
........
r74192 | georg.brandl | 2009-07-24 18:28:38 +0200 (Fr, 24 Jul 2009) | 1 line
Fix arg types of et#.
........
r74193 | georg.brandl | 2009-07-24 18:46:38 +0200 (Fr, 24 Jul 2009) | 1 line
Dont put "void" in signature for nullary functions.
........
r74194 | georg.brandl | 2009-07-24 22:09:46 +0200 (Fr, 24 Jul 2009) | 1 line
#6564: fix section about the two raise syntaxes.
........
r74200 | georg.brandl | 2009-07-25 15:02:15 +0200 (Sa, 25 Jul 2009) | 1 line
#6571: add index entries for more operators.
........
r74205 | georg.brandl | 2009-07-26 15:36:39 +0200 (So, 26 Jul 2009) | 1 line
#6576: fix cross-refs in re docs.
........
2009-10-27 11:34:21 -03:00
|
|
|
sts = os.waitpid(p.pid, 0)[1]
|
2007-08-15 11:28:01 -03:00
|
|
|
|
|
|
|
Notes:
|
|
|
|
|
|
|
|
* Calling the program through the shell is usually not required.
|
|
|
|
|
|
|
|
* It's easier to look at the :attr:`returncode` attribute than the exit status.
|
|
|
|
|
|
|
|
A more realistic example would look like this::
|
|
|
|
|
|
|
|
try:
|
|
|
|
retcode = call("mycmd" + " myarg", shell=True)
|
|
|
|
if retcode < 0:
|
|
|
|
print >>sys.stderr, "Child was terminated by signal", -retcode
|
|
|
|
else:
|
|
|
|
print >>sys.stderr, "Child returned", retcode
|
|
|
|
except OSError, e:
|
|
|
|
print >>sys.stderr, "Execution failed:", e
|
|
|
|
|
|
|
|
|
2009-06-25 14:40:52 -03:00
|
|
|
Replacing the :func:`os.spawn <os.spawnl>` family
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
2007-08-15 11:28:01 -03:00
|
|
|
|
|
|
|
P_NOWAIT example::
|
|
|
|
|
|
|
|
pid = os.spawnlp(os.P_NOWAIT, "/bin/mycmd", "mycmd", "myarg")
|
|
|
|
==>
|
|
|
|
pid = Popen(["/bin/mycmd", "myarg"]).pid
|
|
|
|
|
|
|
|
P_WAIT example::
|
|
|
|
|
|
|
|
retcode = os.spawnlp(os.P_WAIT, "/bin/mycmd", "mycmd", "myarg")
|
|
|
|
==>
|
|
|
|
retcode = call(["/bin/mycmd", "myarg"])
|
|
|
|
|
|
|
|
Vector example::
|
|
|
|
|
|
|
|
os.spawnvp(os.P_NOWAIT, path, args)
|
|
|
|
==>
|
|
|
|
Popen([path] + args[1:])
|
|
|
|
|
|
|
|
Environment example::
|
|
|
|
|
|
|
|
os.spawnlpe(os.P_NOWAIT, "/bin/mycmd", "mycmd", "myarg", env)
|
|
|
|
==>
|
|
|
|
Popen(["/bin/mycmd", "myarg"], env={"PATH": "/usr/bin"})
|
|
|
|
|
|
|
|
|
2009-06-25 14:40:52 -03:00
|
|
|
Replacing :func:`os.popen`, :func:`os.popen2`, :func:`os.popen3`
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
2007-08-15 11:28:01 -03:00
|
|
|
|
|
|
|
::
|
|
|
|
|
2009-09-29 16:18:11 -03:00
|
|
|
pipe = os.popen("cmd", 'r', bufsize)
|
2007-08-15 11:28:01 -03:00
|
|
|
==>
|
2009-09-29 16:18:11 -03:00
|
|
|
pipe = Popen("cmd", shell=True, bufsize=bufsize, stdout=PIPE).stdout
|
2007-08-15 11:28:01 -03:00
|
|
|
|
|
|
|
::
|
|
|
|
|
2009-09-29 16:18:11 -03:00
|
|
|
pipe = os.popen("cmd", 'w', bufsize)
|
2007-08-15 11:28:01 -03:00
|
|
|
==>
|
2009-09-29 16:18:11 -03:00
|
|
|
pipe = Popen("cmd", shell=True, bufsize=bufsize, stdin=PIPE).stdin
|
2007-08-15 11:28:01 -03:00
|
|
|
|
|
|
|
::
|
|
|
|
|
2009-09-29 16:18:11 -03:00
|
|
|
(child_stdin, child_stdout) = os.popen2("cmd", mode, bufsize)
|
2007-08-15 11:28:01 -03:00
|
|
|
==>
|
2009-09-29 16:18:11 -03:00
|
|
|
p = Popen("cmd", shell=True, bufsize=bufsize,
|
2007-08-15 11:28:01 -03:00
|
|
|
stdin=PIPE, stdout=PIPE, close_fds=True)
|
|
|
|
(child_stdin, child_stdout) = (p.stdin, p.stdout)
|
|
|
|
|
|
|
|
::
|
|
|
|
|
|
|
|
(child_stdin,
|
|
|
|
child_stdout,
|
2009-09-29 16:18:11 -03:00
|
|
|
child_stderr) = os.popen3("cmd", mode, bufsize)
|
2007-08-15 11:28:01 -03:00
|
|
|
==>
|
2009-09-29 16:18:11 -03:00
|
|
|
p = Popen("cmd", shell=True, bufsize=bufsize,
|
2007-08-15 11:28:01 -03:00
|
|
|
stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)
|
|
|
|
(child_stdin,
|
|
|
|
child_stdout,
|
|
|
|
child_stderr) = (p.stdin, p.stdout, p.stderr)
|
|
|
|
|
|
|
|
::
|
|
|
|
|
2009-09-29 16:18:11 -03:00
|
|
|
(child_stdin, child_stdout_and_stderr) = os.popen4("cmd", mode,
|
|
|
|
bufsize)
|
2007-08-15 11:28:01 -03:00
|
|
|
==>
|
2009-09-29 16:18:11 -03:00
|
|
|
p = Popen("cmd", shell=True, bufsize=bufsize,
|
2007-08-15 11:28:01 -03:00
|
|
|
stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
|
|
|
|
(child_stdin, child_stdout_and_stderr) = (p.stdin, p.stdout)
|
|
|
|
|
2009-09-29 16:18:11 -03:00
|
|
|
On Unix, os.popen2, os.popen3 and os.popen4 also accept a sequence as
|
|
|
|
the command to execute, in which case arguments will be passed
|
|
|
|
directly to the program without shell intervention. This usage can be
|
|
|
|
replaced as follows::
|
|
|
|
|
|
|
|
(child_stdin, child_stdout) = os.popen2(["/bin/ls", "-l"], mode,
|
|
|
|
bufsize)
|
|
|
|
==>
|
|
|
|
p = Popen(["/bin/ls", "-l"], bufsize=bufsize, stdin=PIPE, stdout=PIPE)
|
|
|
|
(child_stdin, child_stdout) = (p.stdin, p.stdout)
|
|
|
|
|
2009-06-25 14:40:52 -03:00
|
|
|
Return code handling translates as follows::
|
|
|
|
|
2009-09-29 16:18:11 -03:00
|
|
|
pipe = os.popen("cmd", 'w')
|
2009-06-25 14:40:52 -03:00
|
|
|
...
|
|
|
|
rc = pipe.close()
|
2009-09-29 16:18:11 -03:00
|
|
|
if rc != None and rc % 256:
|
2009-06-25 14:40:52 -03:00
|
|
|
print "There were some errors"
|
|
|
|
==>
|
2009-09-29 16:18:11 -03:00
|
|
|
process = Popen("cmd", 'w', shell=True, stdin=PIPE)
|
2009-06-25 14:40:52 -03:00
|
|
|
...
|
|
|
|
process.stdin.close()
|
|
|
|
if process.wait() != 0:
|
|
|
|
print "There were some errors"
|
|
|
|
|
2007-08-15 11:28:01 -03:00
|
|
|
|
2009-06-25 14:40:52 -03:00
|
|
|
Replacing functions from the :mod:`popen2` module
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
2007-08-15 11:28:01 -03:00
|
|
|
|
|
|
|
::
|
|
|
|
|
|
|
|
(child_stdout, child_stdin) = popen2.popen2("somestring", bufsize, mode)
|
|
|
|
==>
|
|
|
|
p = Popen(["somestring"], shell=True, bufsize=bufsize,
|
|
|
|
stdin=PIPE, stdout=PIPE, close_fds=True)
|
|
|
|
(child_stdout, child_stdin) = (p.stdout, p.stdin)
|
|
|
|
|
2009-09-29 16:18:11 -03:00
|
|
|
On Unix, popen2 also accepts a sequence as the command to execute, in
|
|
|
|
which case arguments will be passed directly to the program without
|
|
|
|
shell intervention. This usage can be replaced as follows::
|
2007-08-15 11:28:01 -03:00
|
|
|
|
2009-09-29 16:18:11 -03:00
|
|
|
(child_stdout, child_stdin) = popen2.popen2(["mycmd", "myarg"], bufsize,
|
|
|
|
mode)
|
2007-08-15 11:28:01 -03:00
|
|
|
==>
|
|
|
|
p = Popen(["mycmd", "myarg"], bufsize=bufsize,
|
|
|
|
stdin=PIPE, stdout=PIPE, close_fds=True)
|
|
|
|
(child_stdout, child_stdin) = (p.stdout, p.stdin)
|
|
|
|
|
Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r67571 | georg.brandl | 2008-12-05 10:13:45 +0100 (Fri, 05 Dec 2008) | 2 lines
Use markup.
........
r67574 | georg.brandl | 2008-12-05 10:25:32 +0100 (Fri, 05 Dec 2008) | 2 lines
#4441 followup: Add link to open() docs for Windows.
........
r67575 | georg.brandl | 2008-12-05 12:34:51 +0100 (Fri, 05 Dec 2008) | 2 lines
#4544: add `dedent` to textwrap.__all__.
........
r67576 | georg.brandl | 2008-12-05 13:09:41 +0100 (Fri, 05 Dec 2008) | 2 lines
#4529: fix parser's validation for try-except-finally statements.
........
r67579 | georg.brandl | 2008-12-05 16:29:39 +0100 (Fri, 05 Dec 2008) | 2 lines
#4517: add "special method" glossary entry and clarify when __getattribute__ is bypassed.
........
r67580 | georg.brandl | 2008-12-05 16:32:29 +0100 (Fri, 05 Dec 2008) | 2 lines
#4478: document that copyfile() can raise Error.
........
r67581 | georg.brandl | 2008-12-05 16:42:03 +0100 (Fri, 05 Dec 2008) | 2 lines
#3171: document that *slice are removed in 3k.
........
r67583 | georg.brandl | 2008-12-05 16:52:20 +0100 (Fri, 05 Dec 2008) | 4 lines
Move __import__ to the bottom of the functions list.
It doesn't make sense for such a fundamental document to have
the most obscure function listed at the top.
........
r67591 | georg.brandl | 2008-12-05 19:00:06 +0100 (Fri, 05 Dec 2008) | 2 lines
Followup to #4511: add link from decorator glossary entry to definition.
........
r67597 | georg.brandl | 2008-12-05 20:03:19 +0100 (Fri, 05 Dec 2008) | 2 lines
Remove confusing sentence part.
........
r67608 | georg.brandl | 2008-12-06 12:57:12 +0100 (Sat, 06 Dec 2008) | 2 lines
Follow-up to #4488: document PIPE and STDOUT properly.
........
r67631 | georg.brandl | 2008-12-07 12:54:07 +0100 (Sun, 07 Dec 2008) | 2 lines
Add link to the favicon to the docs.
........
2008-12-07 10:47:12 -04:00
|
|
|
:class:`popen2.Popen3` and :class:`popen2.Popen4` basically work as
|
|
|
|
:class:`subprocess.Popen`, except that:
|
2007-08-15 11:28:01 -03:00
|
|
|
|
Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r67571 | georg.brandl | 2008-12-05 10:13:45 +0100 (Fri, 05 Dec 2008) | 2 lines
Use markup.
........
r67574 | georg.brandl | 2008-12-05 10:25:32 +0100 (Fri, 05 Dec 2008) | 2 lines
#4441 followup: Add link to open() docs for Windows.
........
r67575 | georg.brandl | 2008-12-05 12:34:51 +0100 (Fri, 05 Dec 2008) | 2 lines
#4544: add `dedent` to textwrap.__all__.
........
r67576 | georg.brandl | 2008-12-05 13:09:41 +0100 (Fri, 05 Dec 2008) | 2 lines
#4529: fix parser's validation for try-except-finally statements.
........
r67579 | georg.brandl | 2008-12-05 16:29:39 +0100 (Fri, 05 Dec 2008) | 2 lines
#4517: add "special method" glossary entry and clarify when __getattribute__ is bypassed.
........
r67580 | georg.brandl | 2008-12-05 16:32:29 +0100 (Fri, 05 Dec 2008) | 2 lines
#4478: document that copyfile() can raise Error.
........
r67581 | georg.brandl | 2008-12-05 16:42:03 +0100 (Fri, 05 Dec 2008) | 2 lines
#3171: document that *slice are removed in 3k.
........
r67583 | georg.brandl | 2008-12-05 16:52:20 +0100 (Fri, 05 Dec 2008) | 4 lines
Move __import__ to the bottom of the functions list.
It doesn't make sense for such a fundamental document to have
the most obscure function listed at the top.
........
r67591 | georg.brandl | 2008-12-05 19:00:06 +0100 (Fri, 05 Dec 2008) | 2 lines
Followup to #4511: add link from decorator glossary entry to definition.
........
r67597 | georg.brandl | 2008-12-05 20:03:19 +0100 (Fri, 05 Dec 2008) | 2 lines
Remove confusing sentence part.
........
r67608 | georg.brandl | 2008-12-06 12:57:12 +0100 (Sat, 06 Dec 2008) | 2 lines
Follow-up to #4488: document PIPE and STDOUT properly.
........
r67631 | georg.brandl | 2008-12-07 12:54:07 +0100 (Sun, 07 Dec 2008) | 2 lines
Add link to the favicon to the docs.
........
2008-12-07 10:47:12 -04:00
|
|
|
* :class:`Popen` raises an exception if the execution fails.
|
2007-08-15 11:28:01 -03:00
|
|
|
|
|
|
|
* the *capturestderr* argument is replaced with the *stderr* argument.
|
|
|
|
|
Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r67571 | georg.brandl | 2008-12-05 10:13:45 +0100 (Fri, 05 Dec 2008) | 2 lines
Use markup.
........
r67574 | georg.brandl | 2008-12-05 10:25:32 +0100 (Fri, 05 Dec 2008) | 2 lines
#4441 followup: Add link to open() docs for Windows.
........
r67575 | georg.brandl | 2008-12-05 12:34:51 +0100 (Fri, 05 Dec 2008) | 2 lines
#4544: add `dedent` to textwrap.__all__.
........
r67576 | georg.brandl | 2008-12-05 13:09:41 +0100 (Fri, 05 Dec 2008) | 2 lines
#4529: fix parser's validation for try-except-finally statements.
........
r67579 | georg.brandl | 2008-12-05 16:29:39 +0100 (Fri, 05 Dec 2008) | 2 lines
#4517: add "special method" glossary entry and clarify when __getattribute__ is bypassed.
........
r67580 | georg.brandl | 2008-12-05 16:32:29 +0100 (Fri, 05 Dec 2008) | 2 lines
#4478: document that copyfile() can raise Error.
........
r67581 | georg.brandl | 2008-12-05 16:42:03 +0100 (Fri, 05 Dec 2008) | 2 lines
#3171: document that *slice are removed in 3k.
........
r67583 | georg.brandl | 2008-12-05 16:52:20 +0100 (Fri, 05 Dec 2008) | 4 lines
Move __import__ to the bottom of the functions list.
It doesn't make sense for such a fundamental document to have
the most obscure function listed at the top.
........
r67591 | georg.brandl | 2008-12-05 19:00:06 +0100 (Fri, 05 Dec 2008) | 2 lines
Followup to #4511: add link from decorator glossary entry to definition.
........
r67597 | georg.brandl | 2008-12-05 20:03:19 +0100 (Fri, 05 Dec 2008) | 2 lines
Remove confusing sentence part.
........
r67608 | georg.brandl | 2008-12-06 12:57:12 +0100 (Sat, 06 Dec 2008) | 2 lines
Follow-up to #4488: document PIPE and STDOUT properly.
........
r67631 | georg.brandl | 2008-12-07 12:54:07 +0100 (Sun, 07 Dec 2008) | 2 lines
Add link to the favicon to the docs.
........
2008-12-07 10:47:12 -04:00
|
|
|
* ``stdin=PIPE`` and ``stdout=PIPE`` must be specified.
|
2007-08-15 11:28:01 -03:00
|
|
|
|
|
|
|
* popen2 closes all file descriptors by default, but you have to specify
|
Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r67571 | georg.brandl | 2008-12-05 10:13:45 +0100 (Fri, 05 Dec 2008) | 2 lines
Use markup.
........
r67574 | georg.brandl | 2008-12-05 10:25:32 +0100 (Fri, 05 Dec 2008) | 2 lines
#4441 followup: Add link to open() docs for Windows.
........
r67575 | georg.brandl | 2008-12-05 12:34:51 +0100 (Fri, 05 Dec 2008) | 2 lines
#4544: add `dedent` to textwrap.__all__.
........
r67576 | georg.brandl | 2008-12-05 13:09:41 +0100 (Fri, 05 Dec 2008) | 2 lines
#4529: fix parser's validation for try-except-finally statements.
........
r67579 | georg.brandl | 2008-12-05 16:29:39 +0100 (Fri, 05 Dec 2008) | 2 lines
#4517: add "special method" glossary entry and clarify when __getattribute__ is bypassed.
........
r67580 | georg.brandl | 2008-12-05 16:32:29 +0100 (Fri, 05 Dec 2008) | 2 lines
#4478: document that copyfile() can raise Error.
........
r67581 | georg.brandl | 2008-12-05 16:42:03 +0100 (Fri, 05 Dec 2008) | 2 lines
#3171: document that *slice are removed in 3k.
........
r67583 | georg.brandl | 2008-12-05 16:52:20 +0100 (Fri, 05 Dec 2008) | 4 lines
Move __import__ to the bottom of the functions list.
It doesn't make sense for such a fundamental document to have
the most obscure function listed at the top.
........
r67591 | georg.brandl | 2008-12-05 19:00:06 +0100 (Fri, 05 Dec 2008) | 2 lines
Followup to #4511: add link from decorator glossary entry to definition.
........
r67597 | georg.brandl | 2008-12-05 20:03:19 +0100 (Fri, 05 Dec 2008) | 2 lines
Remove confusing sentence part.
........
r67608 | georg.brandl | 2008-12-06 12:57:12 +0100 (Sat, 06 Dec 2008) | 2 lines
Follow-up to #4488: document PIPE and STDOUT properly.
........
r67631 | georg.brandl | 2008-12-07 12:54:07 +0100 (Sun, 07 Dec 2008) | 2 lines
Add link to the favicon to the docs.
........
2008-12-07 10:47:12 -04:00
|
|
|
``close_fds=True`` with :class:`Popen`.
|
2007-08-15 11:28:01 -03:00
|
|
|
|