cpython: 2184df0e0f89 (original) (raw)

--- a/Doc/library/subprocess.rst +++ b/Doc/library/subprocess.rst @@ -31,7 +31,142 @@ modules and functions can be found in th Using the subprocess Module --------------------------- -This module defines one class called :class:Popen: +The recommended interface to this module is to use the following convenience +functions for all use cases they can handle. For more advanced use cases, the +underlying :class:Popen interface can be used directly. + + +.. function:: call(args, *, stdin=None, stdout=None, stderr=None) +

+

+

+ + +.. function:: check_call(*callargs, **kwargs) +

+

+

+ + +.. function:: check_output(*callargs, **kwargs) +

+

+

+

+ +.. data:: PIPE +

+ +.. data:: STDOUT +

+ +.. _frequently-used-arguments: + +Frequently Used Arguments +^^^^^^^^^^^^^^^^^^^^^^^^^ + +To support a wide variety of use cases, the :class:Popen constructor (and +the convenience functions) accept a large number of optional arguments. For +most typical use cases, many of these arguments can be safely left at their +default values. The arguments that are most commonly needed are: +

+These options, along with all of the other options, are described in more +detail in the :class:Popen constructor documentation. + + +Popen Constuctor +^^^^^^^^^^^^^^^^ + +The underlying process creation and management in this module is handled by +the :class:Popen class. It offers a lot of flexibility so that developers +are able to handle the less common cases not covered by the convenience +functions. .. 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) @@ -126,14 +261,15 @@ This module defines one class called :cl You don't need shell=True to run a batch file, nor to run a console-based executable.

-.. data:: PIPE -

- -.. data:: STDOUT -

- -Convenience Functions -^^^^^^^^^^^^^^^^^^^^^ - -This module also defines the following shortcut functions: - - -.. function:: call(*popenargs, **kwargs) -

-

- - -.. function:: check_call(*popenargs, **kwargs) -

-

- - -.. function:: check_output(*popenargs, **kwargs) -

-

-

- Exceptions ^^^^^^^^^^ @@ -523,12 +578,15 @@ The :mod:subprocess module exposes the Replacing Older Functions with the subprocess Module ---------------------------------------------------- -In this section, "a ==> b" means that b can be used as a replacement for a. +In this section, "a becomes 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

In the following examples, we assume that the subprocess module is imported with "from subprocess import *". @@ -540,8 +598,8 @@ Replacing /bin/sh shell backquote :: output=mycmd myarg

Replacing shell pipeline @@ -550,7 +608,7 @@ Replacing shell pipeline :: output=dmesg | grep hda

+Alternatively, for trusted input, the shell's pipeline may still be used +directly: +

+ Replacing :func:os.system ^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: sts = os.system("mycmd" + " myarg")

Notes:

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -345,6 +345,9 @@ Tests Documentation ------------- +- Issue #13237: Reorganise subprocess documentation to emphasise convenience