OLD | NEW |
1 # coding=utf8 | 1 # coding=utf8 |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 """Collection of subprocess wrapper functions. | 5 """Collection of subprocess wrapper functions. |
6 | 6 |
7 In theory you shouldn't need anything else in subprocess, or this module failed. | 7 In theory you shouldn't need anything else in subprocess, or this module failed. |
8 """ | 8 """ |
9 | 9 |
10 from __future__ import with_statement | 10 from __future__ import with_statement |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 | 226 |
227 | 227 |
228 def capture(args, **kwargs): | 228 def capture(args, **kwargs): |
229 """Captures stdout of a process call and returns it. | 229 """Captures stdout of a process call and returns it. |
230 | 230 |
231 Returns stdout. | 231 Returns stdout. |
232 | 232 |
233 - Discards returncode. | 233 - Discards returncode. |
234 - Discards stderr. By default sets stderr=STDOUT. | 234 - Discards stderr. By default sets stderr=STDOUT. |
235 """ | 235 """ |
| 236 if kwargs.get('stdout') is None: |
| 237 kwargs['stdout'] = PIPE |
236 if kwargs.get('stderr') is None: | 238 if kwargs.get('stderr') is None: |
237 kwargs['stderr'] = STDOUT | 239 kwargs['stderr'] = STDOUT |
238 return call(args, stdout=PIPE, **kwargs)[0][0] | 240 return call(args, **kwargs)[0][0] |
239 | 241 |
240 | 242 |
241 def check_output(args, **kwargs): | 243 def check_output(args, **kwargs): |
242 """Captures stdout of a process call and returns it. | 244 """Captures stdout of a process call and returns it. |
243 | 245 |
244 Returns stdout. | 246 Returns stdout. |
245 | 247 |
246 - Discards stderr. By default sets stderr=STDOUT. | 248 - Discards stderr. By default sets stderr=STDOUT. |
247 - Throws if return code is not 0. | 249 - Throws if return code is not 0. |
248 - Works even prior to python 2.7. | 250 - Works even prior to python 2.7. |
249 """ | 251 """ |
| 252 if kwargs.get('stdout') is None: |
| 253 kwargs['stdout'] = PIPE |
250 if kwargs.get('stderr') is None: | 254 if kwargs.get('stderr') is None: |
251 kwargs['stderr'] = STDOUT | 255 kwargs['stderr'] = STDOUT |
252 return check_call(args, stdout=PIPE, **kwargs)[0] | 256 return check_call(args, **kwargs)[0] |
OLD | NEW |