[issue18649] list2cmdline function in subprocess module handles \" sequence wrong

Richard Oudkerk report at bugs.python.org
Sun Aug 4 15:55:36 CEST 2013


Richard Oudkerk added the comment:

Firstly, list2cmdline() takes a list as its argument, not a string:

  >>> import subprocess
  >>> print subprocess.list2cmdline([r'\"1|2\"'])
  \\\"1|2\\\"

But the problem with passing arguments to a batch file is that cmd.exe parses arguments differently from how normal executables do.  In particular, "|" is treated specially and "^" is used as an escape character.

If you define test.bat as

  @echo off
  echo "%1"

then

  subprocess.call(['test.bat', '1^|2'])

prints

  "1|2"

as expected.

This is a duplicate of http://bugs.python.org/issue1300.

----------
nosy: +sbt
resolution:  -> invalid
stage:  -> committed/rejected
status: open -> closed
type:  -> behavior

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18649>
_______________________________________


More information about the Python-bugs-list mailing list