summaryrefslogtreecommitdiffstats
path: root/Lib/subprocess.py
diff options
context:
space:
mode:
authorTim Golden <mail@timgolden.me.uk>2013-11-03 14:21:29 (GMT)
committerTim Golden <mail@timgolden.me.uk>2013-11-03 14:21:29 (GMT)
commiteb6392b0cbaa864e7ba4c559841c77bf58c284c0 (patch)
treecfae51405e138abb64aa2091432925759cad19e5 /Lib/subprocess.py
parente1b1592fd42f23dadde9e7dbd387f3b43cb5cc15 (diff)
parentab7211f27847ab4e0090cc6bfb815bff4400c898 (diff)
downloadcpython-eb6392b0cbaa864e7ba4c559841c77bf58c284c0.zip
cpython-eb6392b0cbaa864e7ba4c559841c77bf58c284c0.tar.gz
cpython-eb6392b0cbaa864e7ba4c559841c77bf58c284c0.tar.bz2
Issue #10197: merge heads
Diffstat (limited to 'Lib/subprocess.py')
-rw-r--r--Lib/subprocess.py24
1 files changed, 9 insertions, 15 deletions
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
index 23c9ea5..1bfd136 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -700,21 +700,15 @@ def getstatusoutput(cmd):
>>> subprocess.getstatusoutput('/bin/junk')
(256, 'sh: /bin/junk: not found')
"""
- with os.popen('{ ' + cmd + '; } 2>&1', 'r') as pipe:
- try:
- text = pipe.read()
- sts = pipe.close()
- except:
- process = pipe._proc
- process.kill()
- process.wait()
- raise
- if sts is None:
- sts = 0
- if text[-1:] == '\n':
- text = text[:-1]
- return sts, text
-
+ try:
+ data = check_output(cmd, shell=True, universal_newlines=True, stderr=STDOUT)
+ status = 0
+ except CalledProcessError as ex:
+ data = ex.output
+ status = ex.returncode
+ if data[-1:] == '\n':
+ data = data[:-1]
+ return status, data
def getoutput(cmd):
"""Return output (stdout or stderr) of executing cmd in a shell.