OLD | NEW |
---|---|
1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 | 5 |
6 import logging | 6 import logging |
7 import subprocess | 7 import subprocess |
8 | 8 |
9 | 9 |
10 def RunCmd(args, cwd=None): | 10 def RunCmd(args, cwd=None): |
11 """Opens a subprocess to execute a program and returns its return value. | 11 """Opens a subprocess to execute a program and returns its return value. |
12 | 12 |
13 Args: | 13 Args: |
14 args: A string or a sequence of program arguments. The program to execute is | 14 args: A string or a sequence of program arguments. The program to execute is |
15 the string or the first item in the args sequence. | 15 the string or the first item in the args sequence. |
16 cwd: If not None, the subprocess's current directory will be changed to | 16 cwd: If not None, the subprocess's current directory will be changed to |
17 |cwd| before it's executed. | 17 |cwd| before it's executed. |
18 """ | 18 """ |
19 logging.info(str(args) + ' ' + (cwd or '')) | 19 logging.info(str(args) + ' ' + (cwd or '')) |
20 p = subprocess.Popen(args=args, cwd=cwd) | 20 p = subprocess.Popen(args=args, cwd=cwd) |
21 return p.wait() | 21 return p.wait() |
22 | 22 |
23 | 23 |
24 def GetCmdOutput(args, cwd=None): | 24 def GetCmdOutput(args, cwd=None, shell=False): |
25 """Open a subprocess to execute a program and returns its output. | 25 """Open a subprocess to execute a program and returns its output. |
26 | 26 |
27 Args: | 27 Args: |
28 args: A string or a sequence of program arguments. The program to execute is | 28 args: A string or a sequence of program arguments. The program to execute is |
29 the string or the first item in the args sequence. | 29 the string or the first item in the args sequence. |
30 cwd: If not None, the subprocess's current directory will be changed to | 30 cwd: If not None, the subprocess's current directory will be changed to |
Yaron
2012/06/20 17:31:03
Add description for |shell|
| |
31 |cwd| before it's executed. | 31 |cwd| before it's executed. |
32 """ | 32 """ |
33 logging.info(str(args) + ' ' + (cwd or '')) | 33 logging.info(str(args) + ' ' + (cwd or '')) |
34 p = subprocess.Popen(args=args, cwd=cwd, stdout=subprocess.PIPE, | 34 p = subprocess.Popen(args=args, cwd=cwd, stdout=subprocess.PIPE, |
35 stderr=subprocess.PIPE) | 35 stderr=subprocess.PIPE, shell=shell) |
36 stdout, stderr = p.communicate() | 36 stdout, stderr = p.communicate() |
37 if stderr: | 37 if stderr: |
38 logging.critical(stderr) | 38 logging.critical(stderr) |
39 logging.info(stdout[:4096]) # Truncate output longer than 4k. | 39 logging.info(stdout[:4096]) # Truncate output longer than 4k. |
40 return stdout | 40 return stdout |
OLD | NEW |