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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 - The process will be killed after |timeout| seconds and returncode set to | 200 - The process will be killed after |timeout| seconds and returncode set to |
201 TIMED_OUT. | 201 TIMED_OUT. |
202 - Automatically passes stdin content as input so do not specify stdin=PIPE. | 202 - Automatically passes stdin content as input so do not specify stdin=PIPE. |
203 """ | 203 """ |
204 stdin = kwargs.pop('stdin', None) | 204 stdin = kwargs.pop('stdin', None) |
205 if stdin is not None: | 205 if stdin is not None: |
206 if stdin is VOID: | 206 if stdin is VOID: |
207 kwargs['stdin'] = open(os.devnull, 'r') | 207 kwargs['stdin'] = open(os.devnull, 'r') |
208 stdin = None | 208 stdin = None |
209 else: | 209 else: |
210 assert isinstance(stdin, str) | 210 assert isinstance(stdin, basestring) |
211 # When stdin is passed as an argument, use it as the actual input data and | 211 # When stdin is passed as an argument, use it as the actual input data and |
212 # set the Popen() parameter accordingly. | 212 # set the Popen() parameter accordingly. |
213 kwargs['stdin'] = PIPE | 213 kwargs['stdin'] = PIPE |
214 | 214 |
215 if not timeout: | 215 if not timeout: |
216 # Normal workflow. | 216 # Normal workflow. |
217 proc = Popen(args, **kwargs) | 217 proc = Popen(args, **kwargs) |
218 if stdin is not None: | 218 if stdin is not None: |
219 return proc.communicate(stdin), proc.returncode | 219 return proc.communicate(stdin), proc.returncode |
220 else: | 220 else: |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 - Works even prior to python 2.7. | 296 - Works even prior to python 2.7. |
297 - Blocks stdin by default since no output will be visible. | 297 - Blocks stdin by default since no output will be visible. |
298 """ | 298 """ |
299 if kwargs.get('stdin') is None: | 299 if kwargs.get('stdin') is None: |
300 kwargs['stdin'] = VOID | 300 kwargs['stdin'] = VOID |
301 if kwargs.get('stdout') is None: | 301 if kwargs.get('stdout') is None: |
302 kwargs['stdout'] = PIPE | 302 kwargs['stdout'] = PIPE |
303 if kwargs.get('stderr') is None: | 303 if kwargs.get('stderr') is None: |
304 kwargs['stderr'] = STDOUT | 304 kwargs['stderr'] = STDOUT |
305 return check_call(args, **kwargs)[0] | 305 return check_call(args, **kwargs)[0] |
OLD | NEW |