classification
Title: subprocess under windows fails to quote properly when shell=True
Type: behavior Stage: resolved
Components: Library (Lib), Windows Versions: Python 3.2, Python 3.1, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: tim.golden Nosy List: BreamoreBoy, benjamin.peterson, davidfraser, dstanek, ggenellina, tim.golden, weeble
Priority: normal Keywords: patch

Created on 2008-03-16 16:32 by tim.golden, last changed 2010-11-08 10:58 by weeble. This issue is now closed.

Files
File name Uploaded Description Edit
subprocess-r61420.patch tim.golden, 2008-03-16 16:32 Patch against r61240 of Python trunk
subprocess-r61514.patch tim.golden, 2008-03-18 10:37 Patch against r61514 of Python trunk
subprocess.diff ggenellina, 2009-11-15 10:46 Updated patch r76294
Messages (11)
msg63583 - (view) Author: Tim Golden (tim.golden) * (Python committer) Date: 2008-03-16 16:32
The subprocess.Popen function reorganises the command line for process
creation when shell=True is passed in under Windows. It runs the
existing executable & arguments as arguments to %COMSPEC% /c. However
this fails when a second parameter (typically a filename) has an
embedded space. The patch attached adds extra parameters in this case
and adds appropriate unit tests.

Frankly I'm new to unittests and I more-or-less cloned an existing one
to make this work. Happy to be corrected if there's things done wrong &c.
msg63610 - (view) Author: Gabriel Genellina (ggenellina) Date: 2008-03-17 00:59
You aren't testing the modified code, the Popen call should say 
shell=True.

I think that a more PEP8-compliant style would be nice (removing the 
spaces after open and read, and using consistent indentation)
msg63623 - (view) Author: Tim Golden (tim.golden) * (Python committer) Date: 2008-03-17 08:08
Gabriel Genellina wrote:
> Gabriel Genellina <gagsl-py2@yahoo.com.ar> added the comment:
> 
> You aren't testing the modified code, the Popen call should say 
> shell=True.
> 
> I think that a more PEP8-compliant style would be nice (removing the 
> spaces after open and read, and using consistent indentation)

D'oh. Thanks, Gabriel. I'll rework the test and tidy
up the patch.
msg63907 - (view) Author: Tim Golden (tim.golden) * (Python committer) Date: 2008-03-18 10:37
Updated patch against r61514. Test code now PEP8-compliant (I hope). New
tests cover spaces in command and parameter with and without shell=True,
both as simple command string and as list of command/args.
msg95284 - (view) Author: Gabriel Genellina (ggenellina) Date: 2009-11-15 10:46
An up-to-date patch; same contents, but this one can be cleanly 
applied to trunk (as of r76294)
msg95328 - (view) Author: David Fraser (davidfraser) Date: 2009-11-16 08:44
This is closely related to http://bugs.python.org/issue6689
msg111352 - (view) Author: Mark Lawrence (BreamoreBoy) Date: 2010-07-23 16:05
@Tim: @Gabriel: test_subprocess has changed a lot since the patch was done.  If one of you could provide a new patch for 2.7 and py3k I'll test it, thanks.
msg113279 - (view) Author: Tim Golden (tim.golden) * (Python committer) Date: 2010-08-08 16:21
Committed as r83830, r83831, r83832
msg113299 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2010-08-08 19:09
Reverted because of test-breakage on unixes.
msg113674 - (view) Author: Tim Golden (tim.golden) * (Python committer) Date: 2010-08-12 12:35
ReComitted as r83947, r83956, r83957 and this time the buildbots look happy. (At least as regards this change).
msg120727 - (view) Author: Weeble (weeble) Date: 2010-11-08 10:58
Is there any way to write code that's safe with or without this fix? If I have code that currently does this:

subprocess.check_call('""c:\some path with spaces" arg1 arg2 "a quoted arg""', shell=True)

...will it break when running on a version of Python with this fix? Is there any good way to detect whether the running Python has this fix or not?
History
Date User Action Args
2010-11-08 10:58:28weeblesetnosy: + weeble
messages: + msg120727
2010-08-12 12:35:49tim.goldensetstatus: open -> closed
resolution: fixed
messages: + msg113674
2010-08-08 19:09:53benjamin.petersonsetstatus: closed -> open

nosy: + benjamin.peterson
messages: + msg113299

resolution: fixed -> (no value)
2010-08-08 16:21:35tim.goldensetstatus: open -> closed
resolution: fixed
messages: + msg113279

stage: patch review -> resolved
2010-08-06 15:45:31tim.goldensetassignee: tim.golden
components: + Windows
nosy: davidfraser, ggenellina, dstanek, tim.golden, BreamoreBoy
2010-07-31 17:40:45dstaneksetnosy: + dstanek
2010-07-23 16:05:20BreamoreBoysetnosy: + BreamoreBoy

messages: + msg111352
versions: - Python 2.6
2009-11-16 08:44:30davidfrasersetmessages: + msg95328
2009-11-15 10:46:54ggenellinasetfiles: + subprocess.diff

messages: + msg95284
versions: + Python 3.1, Python 2.7, Python 3.2
2009-08-12 07:33:27davidfrasersetnosy: + davidfraser
2009-04-07 23:13:40tleeuwenburg@gmail.comsetstage: patch review
2008-03-18 10:37:19tim.goldensetfiles: + subprocess-r61514.patch
messages: + msg63907
2008-03-17 08:08:41tim.goldensetmessages: + msg63623
title: subprocess under windows fails to quote properly when shell=True -> subprocess under windows fails to quote properly when shell=True
2008-03-17 00:59:31ggenellinasetnosy: + ggenellina
messages: + msg63610
2008-03-16 16:36:27tim.goldensettitle: subprocess under windows fails to quote properly under Windows when shell=True -> subprocess under windows fails to quote properly when shell=True
2008-03-16 16:32:18tim.goldencreate