➜

This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
标题: subprocess: call([arg, arg2], shell=True) vs call(arg+" "+arg2, shell=True)
类型: behavior Stage: resolved
Components: Documentation, Library (Lib) Versions: Python 2.5
process
状态: closed Resolution: duplicate
Dependencies: 后续: patch to subprocess docs to better explain Popen's 'args' argument
View: 6760
分配给: georg.brandl 抄送列表: brian.curtin, georg.brandl, r.david.murray, techtonik
优先级: normal 关键字:

Created on 2010-02-16 12:44 by techtonik, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (11)
msg99401 - (view) Author: anatoly techtonik (techtonik) 日期: 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) 日期: 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) 日期: 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) 日期: 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) 日期: 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) 日期: 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) 日期: 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) 日期: 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) 日期: 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) 日期: 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) 日期: 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.
历史
日期 用户 动作 参数
2022-04-11 14:56:57admin修改github: 52187
2010-02-17 06:58:23techtonik修改消息: + msg99463
2010-02-16 20:41:00r.david.murray修改消息: + msg99437
2010-02-16 20:24:36techtonik修改消息: + msg99436
2010-02-16 20:19:12techtonik修改消息: + msg99435
2010-02-16 18:00:07r.david.murray修改消息: + msg99427
2010-02-16 17:36:57brian.curtin修改消息: + msg99422
2010-02-16 17:20:15techtonik修改消息: + msg99420
2010-02-16 15:36:59brian.curtin修改状态: open -> closed
抄送: + brian.curtin
消息: + msg99418

2010-02-16 15:22:22techtonik修改状态: closed -> open

抄送: + georg.brandl
消息: + msg99416

assignee: georg.brandl
components: + Documentation
2010-02-16 14:44:59r.david.murray修改状态: open -> closed
优先级: normal

消息: + msg99413
抄送: + r.david.murray

后续: patch to subprocess docs to better explain Popen's 'args' argument
type: behavior
resolution: duplicate
stage: resolved
2010-02-16 12:44:48techtonik创建