➜

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
标题: commands.getoutput() does not work on windows
类型: behavior Stage:
Components: Windows Versions: Python 2.7
process
状态: closed Resolution: duplicate
Dependencies: 后续: subprocess.getoutput fails on win32
View: 10197
分配给: 抄送列表: amaury.forgeotdarc, p.fedin, r.david.murray
优先级: normal 关键字:

Created on 2012-06-15 05:53 by p.fedin, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (4)
msg162844 - (view) Author: Pavel Fedin (p.fedin) 日期: 2012-06-15 05:53
commands.getoutput() is broken on Windows. The issue has been detected in v2.7.2, but still persists in v2.7.3:
--- cut ---
Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import commands;
>>> print commands.getoutput("dir");
'{' is not recognized as an internal or external command,
operable program or batch file.
>>>
--- cut ---
 The error message comes from cmd.exe. Looks like Python tries to feed native Windows shell with UNIX-style commands sequence in {...}.
 I believe this is very simple to fix, please take a look at it. Some our internal software croaks because of this.
msg162874 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) 日期: 2012-06-15 08:38
The documentation http://docs.python.org/library/commands.html
prominently says "Platforms: Unix".  This module does not work on Windows.
You should really use the subprocess module:
>>> import subprocess
>>> output = subprocess.check_output("dir", shell=True)
msg162894 - (view) Author: R. David Murray (r.david.murray) * (Python committer) 日期: 2012-06-15 12:38
Hmm.  Maybe issue 10197 should be reclassified as an enhancement...
msg162897 - (view) Author: Pavel Fedin (p.fedin) 日期: 2012-06-15 13:30
I see it's deprecated and dropped, but anyway, why not to fix it to work on Windows? From 10197 i see the fix is quite simple, and there is lots of legacy code i believe.
历史
日期 用户 动作 参数
2022-04-11 14:57:31admin修改github: 59278
2012-06-15 13:30:41p.fedin修改消息: + msg162897
2012-06-15 12:38:49r.david.murray修改标题: commands.getoutput() is broken -> commands.getoutput() does not work on windows
抄送: + r.david.murray

消息: + msg162894

后续: subprocess.getoutput fails on win32
resolution: wont fix -> duplicate
2012-06-15 08:38:47amaury.forgeotdarc修改状态: open -> closed

抄送: + amaury.forgeotdarc
消息: + msg162874

resolution: wont fix
2012-06-15 05:53:20p.fedin创建