Skip to content

subprocess: move shell arguments to a separate keyword param #57406

Closed

Description

@techtonik
mannequin
BPO 13197
Nosy @rhettinger, @vstinner
Superseder
  • bpo-7839: Popen should raise ValueError if pass a string when shell=False or a list when shell=True
  • 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 = None
    closed_at = <Date 2022-03-25.11:42:00.480>
    created_at = <Date 2011-10-17.11:41:11.103>
    labels = ['type-feature', 'library']
    title = 'subprocess: move shell arguments to a separate keyword param'
    updated_at = <Date 2022-03-25.11:42:00.479>
    user = 'https://bugs.python.org/techtonik'

    bugs.python.org fields:

    activity = <Date 2022-03-25.11:42:00.479>
    actor = 'iritkatriel'
    assignee = 'none'
    closed = True
    closed_date = <Date 2022-03-25.11:42:00.480>
    closer = 'iritkatriel'
    components = ['Library (Lib)']
    creation = <Date 2011-10-17.11:41:11.103>
    creator = 'techtonik'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 13197
    keywords = []
    message_count = 6.0
    messages = ['145669', '145670', '145675', '145676', '145877', '145887']
    nosy_count = 6.0
    nosy_names = ['rhettinger', 'vstinner', 'techtonik', 'Arfrever', 'cvrebert', 'rosslagerwall']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '7839'
    type = 'enhancement'
    url = 'https://bugs.python.org/issue13197'
    versions = ['Python 3.3']

    Activity

    1. techtonik commented on Oct 17, 2011

      techtonikmannequin
      MannequinAuthor

      subprocess.Popen(args, shell=shell) is implicitly inconsistent on Unix:

      1. when shell=False, the args should be a list or you'll lose program options
      2. when shell=True, the args should be a string or your program options will be passed to shell itself

      I propose to make consistent behaviour - require args to be a list, and pass shell options in a separate shell_args keyword argument. If it not for python4, then perhaps it can be implemented in PopenShell() and PopenSystem() functions.

      This will also require unification of behaviour across platforms.

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      on Oct 17, 2011
    3. vstinner commented on Oct 17, 2011

      @vstinner
      Member

      Did you read the issue bpo-7839?

    4. techtonik commented on Oct 17, 2011

      techtonikmannequin
      MannequinAuthor

      No. I won't be fixed in 2.7 anyway, and if it can not be fixed, it should be documented at least.

    5. techtonik commented on Oct 17, 2011

      techtonikmannequin
      MannequinAuthor

      Oh, sorry - my attention span is limited under time pressure. bpo-7839 is related, of course. There is a lot of comments, so I'll take a look at it later.

    6. rhettinger commented on Oct 18, 2011

      @rhettinger
      Contributor

      I don't think you can tighten the API at this point. We could however make Popen complain when options are going to be thrown away. Or it could be made more liberal about what is accepts (running shlex on string input or join on list input as needed).

    7. techtonik commented on Oct 19, 2011

      techtonikmannequin
      MannequinAuthor

      List not only needs to be joined, it should be quoted as well. But the biggest problem will be the change of behavior between Python versions which may confuse users even more.

      Perhaps it's a good time to start embedding 'best practice' recipes in manual.

    8. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions