mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
Issue #10197 Rework subprocess.get[status]output to use subprocess functionality and thus to work on Windows. Patch by Nick Coghlan.
This commit is contained in:
commit
ab7211f278
3 changed files with 14 additions and 24 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue