This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rengine
Recipients rengine
Date 2015-04-03.19:04:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1428087893.92.0.437670101484.issue23862@psf.upfronthosting.co.za>
In-reply-to
Content
Using Python 2.7.9

Noticed when I run a subprocess Popen with an argument containing double quotes, it will have a different affect depending on my operating system. 

In Linux, if I run ./runme.py, it will call runme.sh which will append someargs.txt correctly without escaped quotations

In Windows, if I run ./runme.py, it will call runme.bat which will append someargs.txt with escaped quotations

Also in Windows, if I run runme.bat with an argument containing quotations it will append someargs.txt correctly without escaped quotations so this problem seems to be stemming from Python.

===================================== runme.py

#!/usr/bin/python
import sys
import subprocess
import shlex

# works on Linux:
#command_line = "./runme.sh --include=\"check\""

# fails on Windows:
command_line = "runme.bat --include=\"check\""
#command_line = "runme.bat --include=\"check\""

arg = shlex.shlex(command_line)
arg.quotes = '"'
arg.whitespace_split = True
arg.commenters = ''
command_line_args = list(arg)
print command_line_args

command_line_process = subprocess.Popen(
    command_line_args,
    universal_newlines=True,
    stdout=subprocess.PIPE,
    stderr=subprocess.PIPE
)

line = ""
while True:
    line = command_line_process.stdout.readline()
    if line:
        print line
    else:
        break

===================================== runme.bat

echo %*
echo %* >> someargs.txt

===================================== runme.sh

#!/bin/bash
echo $@
echo $@ >> someargs.txt
History
Date User Action Args
2015-04-03 19:04:53renginesetrecipients: + rengine
2015-04-03 19:04:53renginesetmessageid: <1428087893.92.0.437670101484.issue23862@psf.upfronthosting.co.za>
2015-04-03 19:04:53renginelinkissue23862 messages
2015-04-03 19:04:53renginecreate