Charles Duffy
Charles Duffy

Reputation: 295904

Python subprocess not passing curly brackets as arguments on Windows

At the Windows command line, the following behaves exactly as expected:

C:\> c:\cygwin\bin\printf "<%s>\n" "{foo}"
{foo}

From inside a native win32 Python instance, however, the curly brackets are stripped:

>>> subprocess.Popen(['c:\\cygwin\\bin\\printf', '<%s>\n', '{foo}'],
...                  stdout=subprocess.PIPE).communicate()[0].rstrip('\n')
'foo'

What's going on here?

Upvotes: 2

Views: 1418

Answers (1)

Madison May
Madison May

Reputation: 2763

You should be able to use pipes.quote() to resolve this issue: http://docs.python.org/2/library/pipes.html#pipes.quote

Alternatively, if you're on python3, checkout shlex.quotes(): http://docs.python.org/2/library/shlex.html#module-shlex

Upvotes: 2

Related Questions