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
Title: commands.getoutput() does not work on windows
Type: behavior Stage:
Components: Windows Versions: Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: subprocess.getoutput fails on win32
View: 10197
Assigned To: Nosy List: amaury.forgeotdarc, p.fedin, r.david.murray
Priority: normal Keywords:

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) Date: 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) Date: 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) Date: 2012-06-15 12:38
Hmm.  Maybe issue 10197 should be reclassified as an enhancement...
msg162897 - (view) Author: Pavel Fedin (p.fedin) Date: 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.
History
Date User Action Args
2022-04-11 14:57:31adminsetgithub: 59278
2012-06-15 13:30:41p.fedinsetmessages: + msg162897
2012-06-15 12:38:49r.david.murraysettitle: commands.getoutput() is broken -> commands.getoutput() does not work on windows
nosy: + r.david.murray

messages: + msg162894

superseder: subprocess.getoutput fails on win32
resolution: wont fix -> duplicate
2012-06-15 08:38:47amaury.forgeotdarcsetstatus: open -> closed

nosy: + amaury.forgeotdarc
messages: + msg162874

resolution: wont fix
2012-06-15 05:53:20p.fedincreate