[ python-Bugs-506100 ] commands.getstatusoutput(): cmd.exe support
SourceForge.net
noreply at sourceforge.net
Wed Mar 14 09:36:38 CET 2007
Bugs item #506100, was opened at 2002-01-20 18:13
Message generated for change (Comment added) made by gbrandl
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=506100&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Platform-specific
>Status: Closed
>Resolution: Wont Fix
Priority: 5
Private: No
Submitted By: Pierre Rouleau (pierre_rouleau)
Assigned to: Nobody/Anonymous (nobody)
Summary: commands.getstatusoutput(): cmd.exe support
Initial Comment:
##commands.getstatusoutput(): Does not support for DOS-type shells
# -------------------------------------------------------------
#
# Inside commands.py, the getstatusoutput() function is not capable of running a
# DOS-type shell command. The current code assumes that the operating system
# is running a Unix-type shell.
#
# The old code is:
def getstatusoutput(cmd):
"""Return (status, output) of executing cmd in a shell."""
import os
pipe = os.popen('{ ' + cmd + '; } 2>&1', 'r')
text = pipe.read()
sts = pipe.close()
if sts is None: sts = 0
if text[-1:] == '\n': text = text[:-1]
return sts, text
# I propose that we update that code to check the operating system and support
# DOS-style shells (for DOS, NT, OS/2) with the following modified code:
def getstatusoutput(cmd):
"""Return (status, output) of executing cmd in a shell."""
import os
if os.name in ['nt', 'dos', 'os2'] :
# use Dos style command shell for NT, DOS and OS/2
pipe = os.popen(cmd + ' 2>&1', 'r')
else :
# use Unix style for all others
pipe = os.popen('{ ' + cmd + '; } 2>&1', 'r')
text = pipe.read()
sts = pipe.close()
if sts is None: sts = 0
if text[-1:] == '\n': text = text[:-1]
return sts, text
----------------------------------------------------------------------
>Comment By: Georg Brandl (gbrandl)
Date: 2007-03-14 08:36
Message:
Logged In: YES
user_id=849994
Originator: NO
commands.py explicitly states "UNIX only".
Anyway, nowadays you should use the subprocess module for such tasks.
----------------------------------------------------------------------
Comment By: Pierre Rouleau (pierre_rouleau)
Date: 2002-01-24 01:14
Message:
Logged In: YES
user_id=420631
The changed proposed is for DOS-type shells, not DOS itself (as far as I
know pure MS-DOS or PC-DOS
are not supported). But Win32 platforms are (NT, 2000, ...) and they use
the same type of native command
interpreter shell. With the proposed change getstatusoutput() works in
those. cmd.exe is available in NT,
2000 and also in OS/2.
----------------------------------------------------------------------
Comment By: Martin v. Löwis (loewis)
Date: 2002-01-23 08:05
Message:
Logged In: YES
user_id=21627
My first reaction to this was "Is DOS still supported"?
Changing subject to mention cmd.exe (which is not a DOS
application).
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=506100&group_id=5470
More information about the Python-bugs-list
mailing list