Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5352194

Browse files
committed
fix documentation and test of getoutput
it returns both stdout and stderr closes gh-3280
1 parent 9f313b4 commit 5352194

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

IPython/utils/_process_common.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,7 @@ def process_handler(cmd, callback, stderr=subprocess.PIPE):
103103

104104

105105
def getoutput(cmd):
106-
"""Return standard output of executing cmd in a shell.
107-
108-
Accepts the same arguments as os.system().
106+
"""Run a command and return its stdout/stderr as a string.
109107
110108
Parameters
111109
----------
@@ -114,9 +112,12 @@ def getoutput(cmd):
114112
115113
Returns
116114
-------
117-
stdout : str
115+
output : str
116+
A string containing the combination of stdout and stderr from the
117+
subprocess, in whatever order the subprocess originally wrote to its
118+
file descriptors (so the order of the information in this string is the
119+
correct order as would be seen if running the command in a terminal).
118120
"""
119-
120121
out = process_handler(cmd, lambda p: p.communicate()[0], subprocess.STDOUT)
121122
if out is None:
122123
return ''

IPython/utils/tests/test_process.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,11 @@ def test_system_quotes(self):
111111

112112
def test_getoutput(self):
113113
out = getoutput('python "%s"' % self.fname)
114-
self.assertEqual(out, 'on stdout')
114+
# we can't rely on the order the line buffered streams are flushed
115+
try:
116+
self.assertEqual(out, 'on stderron stdout')
117+
except AssertionError:
118+
self.assertEqual(out, 'on stdouton stderr')
115119

116120
def test_getoutput_quoted(self):
117121
out = getoutput('python -c "print (1)"')
@@ -125,7 +129,7 @@ def test_getoutput_quoted2(self):
125129
out = getoutput("python -c 'print (\"1\")'")
126130
self.assertEqual(out.strip(), '1')
127131

128-
def test_getoutput(self):
132+
def test_getoutput_error(self):
129133
out, err = getoutputerror('python "%s"' % self.fname)
130134
self.assertEqual(out, 'on stdout')
131135
self.assertEqual(err, 'on stderr')

0 commit comments

Comments
 (0)