classification
Title: subprocess: call([arg, arg2], shell=True) vs call(arg+" "+arg2, shell=True)
Type: behavior Stage: resolved
Components: Documentation, Library (Lib) Versions: Python 2.5
process
Status: closed Resolution: duplicate
Dependencies: Superseder: patch to subprocess docs to better explain Popen's 'args' argument
View: 6760
Assigned To: georg.brandl Nosy List: brian.curtin, georg.brandl, r.david.murray, techtonik
Priority: normal Keywords:

Created on 2010-02-16 12:44 by techtonik, last changed 2010-02-17 06:58 by techtonik. This issue is now closed.

Messages (11)
msg99401 - (view) Author: anatoly techtonik (techtonik) Date: 2010-02-16 12:44
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.
msg99413 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-02-16 14:44
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 issue 6760).
msg99416 - (view) Author: anatoly techtonik (techtonik) Date: 2010-02-16 15:22
I can't see changes to subprocess.call() docs in issue #6760. I reopen this bug, because call() definitely need a visible note about this significant behavior. I can not reopen #6760

http://docs.python.org/library/subprocess.html#convenience-functions
msg99418 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2010-02-16 15:36
"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.
msg99420 - (view) Author: anatoly techtonik (techtonik) Date: 2010-02-16 17:20
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.
msg99422 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2010-02-16 17:36
"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".
msg99427 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-02-16 18:00
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.)
msg99435 - (view) Author: anatoly techtonik (techtonik) Date: 2010-02-16 20:19
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"])
msg99436 - (view) Author: anatoly techtonik (techtonik) Date: 2010-02-16 20:24
The last one should be:
retcode = call([sys.executable, "diff.py oldfile newfile"])
msg99437 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-02-16 20:41
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.
msg99463 - (view) Author: anatoly techtonik (techtonik) Date: 2010-02-17 06:58
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.
History
Date User Action Args
2010-02-17 06:58:23techtoniksetmessages: + msg99463
2010-02-16 20:41:00r.david.murraysetmessages: + msg99437
2010-02-16 20:24:36techtoniksetmessages: + msg99436
2010-02-16 20:19:12techtoniksetmessages: + msg99435
2010-02-16 18:00:07r.david.murraysetmessages: + msg99427
2010-02-16 17:36:57brian.curtinsetmessages: + msg99422
2010-02-16 17:20:15techtoniksetmessages: + msg99420
2010-02-16 15:36:59brian.curtinsetstatus: open -> closed
nosy: + brian.curtin
messages: + msg99418

2010-02-16 15:22:22techtoniksetstatus: closed -> open

nosy: + georg.brandl
messages: + msg99416

assignee: georg.brandl
components: + Documentation
2010-02-16 14:44:59r.david.murraysetstatus: open -> closed
priority: normal

messages: + msg99413
nosy: + r.david.murray

superseder: patch to subprocess docs to better explain Popen's 'args' argument
type: behavior
resolution: duplicate
stage: resolved
2010-02-16 12:44:48techtonikcreate