The commands.getstatusoutput wraps the command in "{ cmd; } 2>&1".
Needless to say, this is not windows friendly:
import commands
>>> import commands
>>> status, output = commands.getstatusoutput('dir')
>>> print status
1
>>> print output
'{' is not recognized as an internal or external command,
operable program or batch file.
Would it be worthwhile to submit a simple patch to get around this
prejudice? Or is there some overwhelming reason to use subprocess.popen
directly and/or a win32api call instead?
Patched Lib/commands.py
def getstatusoutput(cmd):
"""Return (status, output) of executing cmd in a shell."""
import sys
mswindows = (sys.platform == "win32")
import os
if not mswindows:
cmd = '{ ' + cmd + '; }'
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
*****
The information transmitted is intended only for the person or entity to which
it is addressed and may contain confidential, proprietary, and/or privileged
material. Any review, retransmission, dissemination or other use of, or taking
of any action in reliance upon this information by persons or entities other
than the intended recipient is prohibited. If you received this in error,
please contact the sender and delete the material from all computers. GA623
_______________________________________________
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32