Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subprocess under windows fails to quote properly when shell=True #46557

Closed
tjguk opened this issue Mar 16, 2008 · 11 comments
Closed

subprocess under windows fails to quote properly when shell=True #46557

tjguk opened this issue Mar 16, 2008 · 11 comments
Assignees
Labels
OS-windows stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@tjguk
Copy link
Member

tjguk commented Mar 16, 2008

BPO 2304
Nosy @tjguk, @benjaminp
Files
  • subprocess-r61420.patch: Patch against r61240 of Python trunk
  • subprocess-r61514.patch: Patch against r61514 of Python trunk
  • subprocess.diff: Updated patch r76294
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/tjguk'
    closed_at = <Date 2010-08-12.12:35:49.657>
    created_at = <Date 2008-03-16.16:32:18.146>
    labels = ['type-bug', 'library', 'OS-windows']
    title = 'subprocess under windows fails to quote properly when\tshell=True'
    updated_at = <Date 2010-11-08.10:58:28.008>
    user = 'https://github.com/tjguk'

    bugs.python.org fields:

    activity = <Date 2010-11-08.10:58:28.008>
    actor = 'weeble'
    assignee = 'tim.golden'
    closed = True
    closed_date = <Date 2010-08-12.12:35:49.657>
    closer = 'tim.golden'
    components = ['Library (Lib)', 'Windows']
    creation = <Date 2008-03-16.16:32:18.146>
    creator = 'tim.golden'
    dependencies = []
    files = ['9682', '9725', '15340']
    hgrepos = []
    issue_num = 2304
    keywords = ['patch']
    message_count = 11.0
    messages = ['63583', '63610', '63623', '63907', '95284', '95328', '111352', '113279', '113299', '113674', '120727']
    nosy_count = 7.0
    nosy_names = ['davidfraser', 'ggenellina', 'dstanek', 'tim.golden', 'benjamin.peterson', 'weeble', 'BreamoreBoy']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue2304'
    versions = ['Python 3.1', 'Python 2.7', 'Python 3.2']

    @tjguk
    Copy link
    Member Author

    tjguk commented Mar 16, 2008

    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.

    @tjguk tjguk added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Mar 16, 2008
    @tjguk tjguk changed the title subprocess under windows fails to quote properly under Windows when shell=True subprocess under windows fails to quote properly when shell=True Mar 16, 2008
    @ggenellina
    Copy link
    Mannequin

    ggenellina mannequin commented Mar 17, 2008

    You aren't testing the modified code, the Popen call should say
    shell=True.

    I think that a more PEP-8-compliant style would be nice (removing the
    spaces after open and read, and using consistent indentation)

    @tjguk
    Copy link
    Member Author

    tjguk commented Mar 17, 2008

    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 PEP-8-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.

    @tjguk tjguk changed the title subprocess under windows fails to quote properly when shell=True subprocess under windows fails to quote properly when shell=True Mar 17, 2008
    @tjguk
    Copy link
    Member Author

    tjguk commented Mar 18, 2008

    Updated patch against r61514. Test code now PEP-8-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.

    @ggenellina
    Copy link
    Mannequin

    ggenellina mannequin commented Nov 15, 2009

    An up-to-date patch; same contents, but this one can be cleanly
    applied to trunk (as of r76294)

    @davidfraser
    Copy link
    Mannequin

    davidfraser mannequin commented Nov 16, 2009

    This is closely related to http://bugs.python.org/issue6689

    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented Jul 23, 2010

    @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.

    @tjguk tjguk self-assigned this Aug 6, 2010
    @tjguk
    Copy link
    Member Author

    tjguk commented Aug 8, 2010

    Committed as r83830, r83831, r83832

    @tjguk tjguk closed this as completed Aug 8, 2010
    @benjaminp
    Copy link
    Contributor

    Reverted because of test-breakage on unixes.

    @benjaminp benjaminp reopened this Aug 8, 2010
    @tjguk
    Copy link
    Member Author

    tjguk commented Aug 12, 2010

    ReComitted as r83947, r83956, r83957 and this time the buildbots look happy. (At least as regards this change).

    @tjguk tjguk closed this as completed Aug 12, 2010
    @weeble
    Copy link
    Mannequin

    weeble mannequin commented Nov 8, 2010

    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?

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    OS-windows stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants