| 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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 return out | 252 return out |
| 253 | 253 |
| 254 | 254 |
| 255 def capture(args, **kwargs): | 255 def capture(args, **kwargs): |
| 256 """Captures stdout of a process call and returns it. | 256 """Captures stdout of a process call and returns it. |
| 257 | 257 |
| 258 Returns stdout. | 258 Returns stdout. |
| 259 | 259 |
| 260 - Discards returncode. | 260 - Discards returncode. |
| 261 - Discards stderr. By default sets stderr=STDOUT. | 261 - Discards stderr. By default sets stderr=STDOUT. |
| 262 - Blocks stdin by default since no output will be visible. |
| 262 """ | 263 """ |
| 264 if kwargs.get('stdin') is None: |
| 265 kwargs['stdin'] = VOID |
| 263 if kwargs.get('stdout') is None: | 266 if kwargs.get('stdout') is None: |
| 264 kwargs['stdout'] = PIPE | 267 kwargs['stdout'] = PIPE |
| 265 if kwargs.get('stderr') is None: | 268 if kwargs.get('stderr') is None: |
| 266 kwargs['stderr'] = STDOUT | 269 kwargs['stderr'] = STDOUT |
| 267 return call(args, **kwargs)[0][0] | 270 return call(args, **kwargs)[0][0] |
| 268 | 271 |
| 269 | 272 |
| 270 def check_output(args, **kwargs): | 273 def check_output(args, **kwargs): |
| 271 """Captures stdout of a process call and returns it. | 274 """Captures stdout of a process call and returns it. |
| 272 | 275 |
| 273 Returns stdout. | 276 Returns stdout. |
| 274 | 277 |
| 275 - Discards stderr. By default sets stderr=STDOUT. | 278 - Discards stderr. By default sets stderr=STDOUT. |
| 276 - Throws if return code is not 0. | 279 - Throws if return code is not 0. |
| 277 - Works even prior to python 2.7. | 280 - Works even prior to python 2.7. |
| 281 - Blocks stdin by default since no output will be visible. |
| 278 """ | 282 """ |
| 283 if kwargs.get('stdin') is None: |
| 284 kwargs['stdin'] = VOID |
| 279 if kwargs.get('stdout') is None: | 285 if kwargs.get('stdout') is None: |
| 280 kwargs['stdout'] = PIPE | 286 kwargs['stdout'] = PIPE |
| 281 if kwargs.get('stderr') is None: | 287 if kwargs.get('stderr') is None: |
| 282 kwargs['stderr'] = STDOUT | 288 kwargs['stderr'] = STDOUT |
| 283 return check_call(args, **kwargs)[0] | 289 return check_call(args, **kwargs)[0] |
| OLD | NEW |