diff options
Diffstat (limited to 'build/android/pylib/cmd_helper.py')
-rw-r--r-- | build/android/pylib/cmd_helper.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/build/android/pylib/cmd_helper.py b/build/android/pylib/cmd_helper.py index 8b50130..46b6981 100644 --- a/build/android/pylib/cmd_helper.py +++ b/build/android/pylib/cmd_helper.py @@ -40,11 +40,28 @@ def GetCmdOutput(args, cwd=None, shell=False): Captures and returns the command's stdout. Prints the command's stderr to logger (which defaults to stdout). """ + (_, output) = GetCmdStatusAndOutput(args, cwd, shell) + return output + +def GetCmdStatusAndOutput(args, cwd=None, shell=False): + """Executes a subprocess and returns its exit code and 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. + shell: Whether to execute args as a shell command. + + Returns: + The tuple (exit code, output). + """ logging.info(str(args) + ' ' + (cwd or '')) p = subprocess.Popen(args=args, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=shell) stdout, stderr = p.communicate() + exit_code = p.returncode if stderr: logging.critical(stderr) logging.info(stdout[:4096]) # Truncate output longer than 4k. - return stdout + return (exit_code, stdout) |