@@ -93,12 +93,10 @@ This module defines one class called :class:`Popen`:
9393 *shell=False * does not suffer from this vulnerability; the above Note may be
9494 helpful in getting code using *shell=False * to work.
9595
96- On Windows: the :class: `Popen ` class uses CreateProcess() to execute the child
97- program, which operates on strings. If *args * is a sequence, it will be
98- converted to a string using the :meth: `list2cmdline ` method. Please note that
99- not all MS Windows applications interpret the command line the same way:
100- :meth: `list2cmdline ` is designed for applications using the same rules as the MS
101- C runtime.
96+ On Windows: the :class: `Popen ` class uses CreateProcess() to execute the
97+ child program, which operates on strings. If *args * is a sequence, it will
98+ be converted to a string in a manner described in
99+ :ref: `converting-argument-sequence `.
102100
103101 *bufsize *, if given, has the same meaning as the corresponding argument to the
104102 built-in open() function: :const: `0 ` means unbuffered, :const: `1 ` means line
@@ -609,3 +607,36 @@ Replacing functions from the :mod:`popen2` module
609607
610608* popen2 closes all file descriptors by default, but you have to specify
611609 ``close_fds=True `` with :class: `Popen `.
610+
611+ Notes
612+ -----
613+
614+ .. _converting-argument-sequence :
615+
616+ Converting an argument sequence to a string on Windows
617+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
618+
619+ On Windows, an *args * sequence is converted to a string that can be parsed
620+ using the following rules (which correspond to the rules used by the MS C
621+ runtime):
622+
623+ 1. Arguments are delimited by white space, which is either a
624+ space or a tab.
625+
626+ 2. A string surrounded by double quotation marks is
627+ interpreted as a single argument, regardless of white space
628+ contained within. A quoted string can be embedded in an
629+ argument.
630+
631+ 3. A double quotation mark preceded by a backslash is
632+ interpreted as a literal double quotation mark.
633+
634+ 4. Backslashes are interpreted literally, unless they
635+ immediately precede a double quotation mark.
636+
637+ 5. If backslashes immediately precede a double quotation mark,
638+ every pair of backslashes is interpreted as a literal
639+ backslash. If the number of backslashes is odd, the last
640+ backslash escapes the next double quotation mark as
641+ described in rule 3.
642+
0 commit comments