Show More
@@ -103,9 +103,7 b' def process_handler(cmd, callback, stderr=subprocess.PIPE):' | |||
|
103 | 103 | |
|
104 | 104 | |
|
105 | 105 | 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. | |
|
109 | 107 | |
|
110 | 108 | Parameters |
|
111 | 109 | ---------- |
@@ -114,9 +112,12 b' def getoutput(cmd):' | |||
|
114 | 112 | |
|
115 | 113 | Returns |
|
116 | 114 | ------- |
|
117 |
|
|
|
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). | |
|
118 | 120 | """ |
|
119 | ||
|
120 | 121 | out = process_handler(cmd, lambda p: p.communicate()[0], subprocess.STDOUT) |
|
121 | 122 | if out is None: |
|
122 | 123 | return '' |
@@ -111,7 +111,11 b' class SubProcessTestCase(TestCase, tt.TempFileMixin):' | |||
|
111 | 111 | |
|
112 | 112 | def test_getoutput(self): |
|
113 | 113 | 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') | |
|
115 | 119 | |
|
116 | 120 | def test_getoutput_quoted(self): |
|
117 | 121 | out = getoutput('python -c "print (1)"') |
@@ -125,7 +129,7 b' class SubProcessTestCase(TestCase, tt.TempFileMixin):' | |||
|
125 | 129 | out = getoutput("python -c 'print (\"1\")'") |
|
126 | 130 | self.assertEqual(out.strip(), '1') |
|
127 | 131 | |
|
128 | def test_getoutput(self): | |
|
132 | def test_getoutput_error(self): | |
|
129 | 133 | out, err = getoutputerror('python "%s"' % self.fname) |
|
130 | 134 | self.assertEqual(out, 'on stdout') |
|
131 | 135 | self.assertEqual(err, 'on stderr') |
General Comments 0
You need to be logged in to leave comments.
Login now