mirror of https://github.com/python/cpython
Issue #10197: merge heads
This commit is contained in:
commit
49667f09a7
|
@ -681,21 +681,15 @@ def getstatusoutput(cmd):
|
||||||
>>> subprocess.getstatusoutput('/bin/junk')
|
>>> subprocess.getstatusoutput('/bin/junk')
|
||||||
(256, 'sh: /bin/junk: not found')
|
(256, 'sh: /bin/junk: not found')
|
||||||
"""
|
"""
|
||||||
with os.popen('{ ' + cmd + '; } 2>&1', 'r') as pipe:
|
try:
|
||||||
try:
|
data = check_output(cmd, shell=True, universal_newlines=True, stderr=STDOUT)
|
||||||
text = pipe.read()
|
status = 0
|
||||||
sts = pipe.close()
|
except CalledProcessError as ex:
|
||||||
except:
|
data = ex.output
|
||||||
process = pipe._proc
|
status = ex.returncode
|
||||||
process.kill()
|
if data[-1:] == '\n':
|
||||||
process.wait()
|
data = data[:-1]
|
||||||
raise
|
return status, data
|
||||||
if sts is None:
|
|
||||||
sts = 0
|
|
||||||
if text[-1:] == '\n':
|
|
||||||
text = text[:-1]
|
|
||||||
return sts, text
|
|
||||||
|
|
||||||
|
|
||||||
def getoutput(cmd):
|
def getoutput(cmd):
|
||||||
"""Return output (stdout or stderr) of executing cmd in a shell.
|
"""Return output (stdout or stderr) of executing cmd in a shell.
|
||||||
|
|
|
@ -2133,13 +2133,6 @@ class Win32ProcessTestCase(BaseTestCase):
|
||||||
def test_terminate_dead(self):
|
def test_terminate_dead(self):
|
||||||
self._kill_dead_process('terminate')
|
self._kill_dead_process('terminate')
|
||||||
|
|
||||||
|
|
||||||
# The module says:
|
|
||||||
# "NB This only works (and is only relevant) for UNIX."
|
|
||||||
#
|
|
||||||
# Actually, getoutput should work on any platform with an os.popen, but
|
|
||||||
# I'll take the comment as given, and skip this suite.
|
|
||||||
@unittest.skipUnless(os.name == 'posix', "only relevant for UNIX")
|
|
||||||
class CommandTests(unittest.TestCase):
|
class CommandTests(unittest.TestCase):
|
||||||
def test_getoutput(self):
|
def test_getoutput(self):
|
||||||
self.assertEqual(subprocess.getoutput('echo xyzzy'), 'xyzzy')
|
self.assertEqual(subprocess.getoutput('echo xyzzy'), 'xyzzy')
|
||||||
|
@ -2153,8 +2146,8 @@ class CommandTests(unittest.TestCase):
|
||||||
try:
|
try:
|
||||||
dir = tempfile.mkdtemp()
|
dir = tempfile.mkdtemp()
|
||||||
name = os.path.join(dir, "foo")
|
name = os.path.join(dir, "foo")
|
||||||
|
status, output = subprocess.getstatusoutput(
|
||||||
status, output = subprocess.getstatusoutput('cat ' + name)
|
("type " if mswindows else "cat ") + name)
|
||||||
self.assertNotEqual(status, 0)
|
self.assertNotEqual(status, 0)
|
||||||
finally:
|
finally:
|
||||||
if dir is not None:
|
if dir is not None:
|
||||||
|
|
|
@ -16,6 +16,9 @@ Library
|
||||||
- Issue #6157: Fixed tkinter.Text.debug(). Original patch by Guilherme Polo.
|
- Issue #6157: Fixed tkinter.Text.debug(). Original patch by Guilherme Polo.
|
||||||
|
|
||||||
- Issue #6160: The bbox() method of tkinter.Spinbox now returns a tuple of
|
- Issue #6160: The bbox() method of tkinter.Spinbox now returns a tuple of
|
||||||
|
|
||||||
|
- Issue #10197: Rework subprocess.get[status]output to use subprocess
|
||||||
|
functionality and thus to work on Windows. Patch by Nick Coghlan.
|
||||||
integers instead of a string. Based on patch by Guilherme Polo.
|
integers instead of a string. Based on patch by Guilherme Polo.
|
||||||
|
|
||||||
- Issue #19286: Directories in ``package_data`` are no longer added to
|
- Issue #19286: Directories in ``package_data`` are no longer added to
|
||||||
|
|
Loading…
Reference in New Issue