Skip to content

subprocess: call([arg, arg2], shell=True) vs call(arg+" "+arg2, shell=True) #52187

Closed

Description

@techtonik
mannequin
BPO 7939
Nosy @birkenfeld, @bitdancer, @briancurtin
Superseder
  • bpo-6760: patch to subprocess docs to better explain Popen's 'args' argument
  • 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/birkenfeld'
    closed_at = <Date 2010-02-16.15:36:59.024>
    created_at = <Date 2010-02-16.12:44:47.925>
    labels = ['type-bug', 'library', 'docs']
    title = 'subprocess: call([arg, arg2], shell=True) vs call(arg+" "+arg2, shell=True)'
    updated_at = <Date 2010-02-17.06:58:23.576>
    user = 'https://bugs.python.org/techtonik'

    bugs.python.org fields:

    activity = <Date 2010-02-17.06:58:23.576>
    actor = 'techtonik'
    assignee = 'georg.brandl'
    closed = True
    closed_date = <Date 2010-02-16.15:36:59.024>
    closer = 'brian.curtin'
    components = ['Documentation', 'Library (Lib)']
    creation = <Date 2010-02-16.12:44:47.925>
    creator = 'techtonik'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 7939
    keywords = []
    message_count = 11.0
    messages = ['99401', '99413', '99416', '99418', '99420', '99422', '99427', '99435', '99436', '99437', '99463']
    nosy_count = 4.0
    nosy_names = ['georg.brandl', 'techtonik', 'r.david.murray', 'brian.curtin']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '6760'
    type = 'behavior'
    url = 'https://bugs.python.org/issue7939'
    versions = ['Python 2.5']

    Activity

    1. techtonik commented on Feb 16, 2010

      techtonikmannequin
      MannequinAuthor

      subprocess.call([arg, arg2], shell=True) is different from subprocess.call(arg+" "+arg2, shell=True)

      The last one executed correctly, the first one fails on Python 2.5.2 Debian Lenny. Why these should be different? Seems like a bug to me.

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      on Feb 16, 2010
    3. bitdancer commented on Feb 16, 2010

      @bitdancer
      Member

      If by "fail" you mean "doesn't execute the command in the way I expected", then I believe you will be enlightened by reading the recent updates to the Popen documentation (see bpo-6760).

    4. techtonik commented on Feb 16, 2010

      techtonikmannequin
      MannequinAuthor

      I can't see changes to subprocess.call() docs in issue bpo-6760. I reopen this bug, because call() definitely need a visible note about this significant behavior. I can not reopen bpo-6760

      http://docs.python.org/library/subprocess.html#convenience-functions

    5. briancurtin commented on Feb 16, 2010

      @briancurtin
      Member

      "The arguments are the same as for the Popen constructor"

      subprocess.call uses subprocess.Popen, so you should refer to Popen and it's examples for specifics.

    6. techtonik commented on Feb 16, 2010

      techtonikmannequin
      MannequinAuthor

      I still do not agree. There should be a note in call() documentation, because users will waste their time experiencing the bug before reading documentation again.

      If you can't make something just work without rereading the whole doc - that's not pythonic.

    7. briancurtin commented on Feb 16, 2010

      @briancurtin
      Member

      "This module also defines two shortcut functions"

      I think given that we say the calls are shortcuts, and that their arguments are the same as Popen, I take that to mean that subprocess.call experiences the same situations as subprocess.Popen.

      If any change has to be made, I could get on board with changing "two shortcut functions" to "two Popen shortcut functions".

    8. bitdancer commented on Feb 16, 2010

      @bitdancer
      Member

      You can't even use call or check_call without referencing the Popen constructor documentation, so I'm not sure what you are advocating, Anatoly. We certainly don't want to repeat the Popen documentation in full for each convenience function, and if we aren't doing that it seems to me that the current one line redirect to the full Popen docs is the right thing to do. I have, however, turned those references into active links. so that all you have to do is click on Popen to get bounced up to the full docs. (Change made in trunk in r78206, it will get copied to the other branches eventually.)

    9. techtonik commented on Feb 16, 2010

      techtonikmannequin
      MannequinAuthor

      Thanks. That should be enough, although I wouldn't mind against more prominent notice to urge users to go and see Popen parameters. I would also add a second example to allow users see the difference. For instance, how to execute another Python script:

      retcode = call("diff.py oldfile newfile", shell=True)
      retcode = call([sys.executable], ["diff.py oldfile newfile"])
    10. techtonik commented on Feb 16, 2010

      techtonikmannequin
      MannequinAuthor

      The last one should be:
      retcode = call([sys.executable, "diff.py oldfile newfile"])

    11. bitdancer commented on Feb 16, 2010

      @bitdancer
      Member

      I think you should reread the Popen docs carefully :)

      That example should be:

      call([sys.executable, 'diff.py', 'oldfile', 'newfile'])

      And there are examples of that call format in the Popen docs, as well as the explanation of exactly how to format the list correctly. So again, I don't think it is a good idea to try to duplicate that in the call/check_call docs.

    12. techtonik commented on Feb 17, 2010

      techtonikmannequin
      MannequinAuthor

      You are right - I should read the docs, but one of the outstanding features of Python is that in many cases you can test the code faster than read documentation. =) It would help if ["ls", "-la"] example included third argument thus fully covering the concept.

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

    Labels

    docsDocumentation in the Doc dirstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions