diff options
author | michaelbai@google.com <michaelbai@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-20 16:20:47 +0000 |
---|---|---|
committer | michaelbai@google.com <michaelbai@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-20 16:20:47 +0000 |
commit | 360ded8150e6868e6906e9c19dfcbf9823d2c115 (patch) | |
tree | a2d3f47b12ce72dcdcb7a133288b30304513b3b9 /build/android/cmd_helper.py | |
parent | caf8deb860d5e3fa31a4620016303362a5edcb18 (diff) | |
download | chromium_src-360ded8150e6868e6906e9c19dfcbf9823d2c115.zip chromium_src-360ded8150e6868e6906e9c19dfcbf9823d2c115.tar.gz chromium_src-360ded8150e6868e6906e9c19dfcbf9823d2c115.tar.bz2 |
Upstream: Test scripts for Android (phase 1)
These are the utilities
BUG=
TEST=
Review URL: http://codereview.chromium.org/8356013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106507 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'build/android/cmd_helper.py')
-rw-r--r-- | build/android/cmd_helper.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/build/android/cmd_helper.py b/build/android/cmd_helper.py new file mode 100644 index 0000000..bedab94 --- /dev/null +++ b/build/android/cmd_helper.py @@ -0,0 +1,41 @@ +#!/usr/bin/python +# Copyright (c) 2011 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + + +import logging +import subprocess + + +def RunCmd(args, cwd=None): + """Opens a subprocess to execute a program and returns its return value. + + Args: + args: A string or a sequence of program arguments. The program to execute is + the string or the first item in the args sequence. + cwd: If not None, the subprocess's current directory will be changed to + |cwd| before it's executed. + """ + logging.info(str(args) + ' ' + (cwd or '')) + p = subprocess.Popen(args=args, cwd=cwd) + return p.wait() + + +def GetCmdOutput(args, cwd=None): + """Open a subprocess to execute a program and returns its output. + + Args: + args: A string or a sequence of program arguments. The program to execute is + the string or the first item in the args sequence. + cwd: If not None, the subprocess's current directory will be changed to + |cwd| before it's executed. + """ + logging.info(str(args) + ' ' + (cwd or '')) + p = subprocess.Popen(args=args, cwd=cwd, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + stdout, stderr = p.communicate() + if stderr: + logging.critical(stderr) + logging.info(stdout[:4096]) # Truncate output longer than 4k. + return stdout |