Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4a4a02b

Browse files
committed
Issue #16115: Make further improvements to subprocess.Popen() documentation.
1 parent a1ff83e commit 4a4a02b

1 file changed

Lines changed: 25 additions & 17 deletions

File tree

Doc/library/subprocess.rst

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -286,19 +286,27 @@ are able to handle the less common cases not covered by the convenience
286286
functions.
287287

288288

289-
.. class:: Popen(args, bufsize=0, executable=None, stdin=None, stdout=None, stderr=None, preexec_fn=None, close_fds=True, shell=False, cwd=None, env=None, universal_newlines=False, startupinfo=None, creationflags=0, restore_signals=True, start_new_session=False, pass_fds=())
289+
.. class:: Popen(args, bufsize=0, executable=None, stdin=None, stdout=None, \
290+
stderr=None, preexec_fn=None, close_fds=True, shell=False, \
291+
cwd=None, env=None, universal_newlines=False, \
292+
startupinfo=None, creationflags=0, restore_signals=True, \
293+
start_new_session=False, pass_fds=())
290294

291-
Arguments are:
295+
Execute a child program in a new process. On Unix, the class uses
296+
:meth:`os.execvp`-like behavior to execute the child program. On Windows,
297+
the class uses the Windows ``CreateProcess()`` function. The arguments to
298+
:class:`Popen` are as follows.
292299

293300
*args* should be a sequence of program arguments or else a single string.
294301
By default, the program to execute is the first item in *args* if *args* is
295-
a sequence and the string itself if *args* is a string. However, see the
296-
*shell* and *executable* arguments for differences from this behavior.
302+
a sequence. If *args* is a string, the interpretation is
303+
platform-dependent and described below. See the *shell* and *executable*
304+
arguments for additional differences from the default behavior. Unless
305+
otherwise stated, it is recommended to pass *args* as a sequence.
297306

298-
On Unix, the :class:`Popen` class uses :meth:`os.execvp`-like behavior to
299-
execute the child program. If *args* is a string, the string is
300-
interpreted as the name or path of the program to execute; this only works
301-
if the program is being given no arguments.
307+
On Unix, if *args* is a string, the string is interpreted as the name or
308+
path of the program to execute. However, this can only be done if not
309+
passing arguments to the program.
302310

303311
.. note::
304312

@@ -319,14 +327,13 @@ functions.
319327
used in the shell (such as filenames containing spaces or the *echo* command
320328
shown above) are single list elements.
321329

322-
On Windows, the :class:`Popen` class uses ``CreateProcess()`` to
323-
execute the child program, which operates on strings. If *args* is a
324-
sequence, it will be converted to a string in a manner described in
325-
:ref:`converting-argument-sequence`.
330+
On Windows, if *args* is a sequence, it will be converted to a string in a
331+
manner described in :ref:`converting-argument-sequence`. This is because
332+
the underlying ``CreateProcess()`` operates on strings.
326333

327334
The *shell* argument (which defaults to *False*) specifies whether to use
328-
the shell as the program to execute. It is recommended to pass *args* as a
329-
sequence if *shell* is *False* and as a string if *shell* is *True*.
335+
the shell as the program to execute. If *shell* is *True*, it is
336+
recommended to pass *args* as a string rather than as a sequence.
330337

331338
On Unix with ``shell=True``, the shell defaults to :file:`/bin/sh`. If
332339
*args* is a string, the string specifies the command
@@ -365,9 +372,10 @@ functions.
365372

366373
The *executable* argument specifies a replacement program to execute. It
367374
is very seldom needed. When ``shell=False``, *executable* replaces the
368-
program to execute specified by *args*. However, the *args* program is
369-
still treated by most programs as the command name, which can then be
370-
different from the program actually executed. On Unix, the *args* name
375+
program to execute specified by *args*. However, the original *args* is
376+
still passed to the program. Most programs treat the program specified
377+
by *args* as the command name, which can then be different from the program
378+
actually executed. On Unix, the *args* name
371379
becomes the display name for the executable in utilities such as
372380
:program:`ps`. If ``shell=True``, on Unix the *executable* argument
373381
specifies a replacement shell for the default :file:`/bin/sh`.

0 commit comments

Comments
 (0)