homepage

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.

Author eric.araujo
Recipients brian.curtin, eric.araujo, jldm, r.david.murray
Date 2010年12月03日.00:49:26
SpamBayes Score 2.7549157e-07
Marked as misclassified No
Message-id <1291337370.48.0.205234486291.issue10197@psf.upfronthosting.co.za>
In-reply-to
Content
My idea is simply using Popen with appropriate args for stdout and stderr instead of using a shell command with redirections:
--- Lib/subprocess.py (révision 86943)
+++ Lib/subprocess.py (copie de travail)
@@ -560,11 +560,7 @@
 return ''.join(result)
-# Various tools for executing commands and looking at their output and status.
-#
-# NB This only works (and is only relevant) for UNIX.
-
-def getstatusoutput(cmd):
+def getstatusoutput(cmd, shell=True):
 """Return (status, output) of executing cmd in a shell.
 Execute the string 'cmd' in a shell with os.popen() and return a 2-tuple
@@ -581,14 +577,21 @@
 >>> subprocess.getstatusoutput('/bin/junk')
 (256, 'sh: /bin/junk: not found')
 """
- 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]
+ # Wish I could use with...
+ popen = Popen(cmd, shell=shell, stdout=PIPE, stderr=STDOUT)
+ sts = popen.communicate() #or wait() or whatever is the right thing
+ try:
+ text = process.stdout.read()
+ finally:
+ process.stdout.close()
+ if sts is None:
+ sts = 0
+ if text.endswith('\n'):
+ text = text[:-1]
 return sts, text
(The new "shell" argument is icing on the cake, allowing us to later support a list as cmd argument like Popen does.)
History
Date User Action Args
2010年12月03日 00:49:30eric.araujosetrecipients: + eric.araujo, r.david.murray, brian.curtin, jldm
2010年12月03日 00:49:30eric.araujosetmessageid: <1291337370.48.0.205234486291.issue10197@psf.upfronthosting.co.za>
2010年12月03日 00:49:27eric.araujolinkissue10197 messages
2010年12月03日 00:49:26eric.araujocreate

AltStyle によって変換されたページ (->オリジナル) /