OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/python |
| 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 |
| 4 # found in the LICENSE file. |
| 5 |
| 6 |
| 7 import logging |
| 8 import subprocess |
| 9 |
| 10 |
| 11 def RunCmd(args, cwd=None): |
| 12 """Opens a subprocess to execute a program and returns its return value. |
| 13 |
| 14 Args: |
| 15 args: A string or a sequence of program arguments. The program to execute is |
| 16 the string or the first item in the args sequence. |
| 17 cwd: If not None, the subprocess's current directory will be changed to |
| 18 |cwd| before it's executed. |
| 19 """ |
| 20 logging.info(str(args) + ' ' + (cwd or '')) |
| 21 p = subprocess.Popen(args=args, cwd=cwd) |
| 22 return p.wait() |
| 23 |
| 24 |
| 25 def GetCmdOutput(args, cwd=None): |
| 26 """Open a subprocess to execute a program and returns its output. |
| 27 |
| 28 Args: |
| 29 args: A string or a sequence of program arguments. The program to execute is |
| 30 the string or the first item in the args sequence. |
| 31 cwd: If not None, the subprocess's current directory will be changed to |
| 32 |cwd| before it's executed. |
| 33 """ |
| 34 logging.info(str(args) + ' ' + (cwd or '')) |
| 35 p = subprocess.Popen(args=args, cwd=cwd, stdout=subprocess.PIPE, |
| 36 stderr=subprocess.PIPE) |
| 37 stdout, stderr = p.communicate() |
| 38 if stderr: |
| 39 logging.critical(stderr) |
| 40 logging.info(stdout[:4096]) # Truncate output longer than 4k. |
| 41 return stdout |
OLD | NEW |