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: Subprocess.getstatusoutput Fails Executing 'dir' Command on Windows
Type: behavior Stage:
Components: Versions:
process
Status: closed Resolution: not a bug
Dependencies: Superseder: subprocess.getoutput fails on win32
View: 10197
Assigned To: Nosy List: matthieu.labbe, mrwizard82d1, orsenthil, ssbarnea
Priority: normal Keywords:

Created on 2009-04-21 15:49 by mrwizard82d1, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (6)
msg86242 - (view) Author: Lawrence Allan Jones (mrwizard82d1) Date: 2009-04-21 15:49
When attempting to use the subprocess.getstatusoutput() function on
Windows, I noticed an unusual error message:
"'{' is not recognized as an internal or external command, 
operable program or batch file."

When the output contained this message, the status was always 256.

From the interactive prompt, I performed the following:
Python 3.0.1 (r301:69561, Feb 13 2009, 20:04:18) [MSC v.1500 32 bit
(Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> cmdline = 'dir'
>>> (status, output) = subprocess.getstatusoutput(cmdline)
>>> status
256
>>> output
"'{' is not recognized as an internal or external command,\noperable
program or
batch file."
>>>

I think this is an error (but it is possible I misunderstand the
documentation for the function :) .)
msg86243 - (view) Author: Lawrence Allan Jones (mrwizard82d1) Date: 2009-04-21 15:56
Oops: user error. The manual states that subprocess.getstatusoutput() is
only open under Unix. Somehow :) I missed this note.

Sorry for wasting bandwidth.
msg91005 - (view) Author: Sorin Sbarnea (ssbarnea) * Date: 2009-07-28 11:17
Also the same issue does apply for command.getstatusoutput in Python 2.6.

Maybe this bug should be reopened and solved by adding a platform check
in the module. Also the documentation does not specify what would be the
right multiplatform alternative.

Anyway, the current result it's clearly not the expected behavior and
does not give any hint regarding the source of the problem or possible
solutions.
msg91011 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2009-07-28 17:20
sorin:

You meant the commands module, correct?
It is well documented in the commands reference:
http://docs.python.org/library/commands.html

* It is applicable to unix only.
* the getstatusoutput is moved to subprocess in 3x.
msg91013 - (view) Author: Sorin Sbarnea (ssbarnea) * Date: 2009-07-28 18:17
If I made a patch that will raise an error if you include commands
module under Windows will you include it - this will safe others time.
msg110424 - (view) Author: Matthieu Labbé (matthieu.labbe) Date: 2010-07-16 10:01
I think this is a bug: The doc says "Availability: UNIX." but it is *available* under Windows and gives an unexpected error message.

I see several way to fix this:
1) Fix the doc: "Supported only on UNIX. Behavior on other platforms is undefined."
2) Make subprocess.getstatusoutput (and subprocess.getoutput) unavailable on non-supported platforms. (Same behavior as the 'os' module.) 
3) Make these convenience functions multiplatform using subprocess.Popen.

I think the best thing to do is #3. What do you think?
History
Date User Action Args
2022-04-11 14:56:48adminsetgithub: 50058
2012-08-20 03:57:25r.david.murraysetsuperseder: subprocess.getoutput fails on win32
2010-07-16 10:01:44matthieu.labbesetnosy: + matthieu.labbe
messages: + msg110424
2009-07-28 18:17:41ssbarneasetmessages: + msg91013
2009-07-28 17:20:49orsenthilsetnosy: + orsenthil
messages: + msg91011
2009-07-28 11:17:22ssbarneasettype: behavior

messages: + msg91005
nosy: + ssbarnea
2009-04-21 18:42:13benjamin.petersonsetresolution: not a bug
2009-04-21 15:56:03mrwizard82d1setstatus: open -> closed

messages: + msg86243
2009-04-21 15:49:32mrwizard82d1create