Index: build/android/pylib/cmd_helper.py |
diff --git a/build/android/pylib/cmd_helper.py b/build/android/pylib/cmd_helper.py |
index 8b501309060bc5943afbc9c7e96fb1ce97eac397..1eddf5bdfed809c21bfc05d0e0875f6407ce843e 100644 |
--- a/build/android/pylib/cmd_helper.py |
+++ b/build/android/pylib/cmd_helper.py |
@@ -48,3 +48,26 @@ def GetCmdOutput(args, cwd=None, shell=False): |
logging.critical(stderr) |
logging.info(stdout[:4096]) # Truncate output longer than 4k. |
return stdout |
+ |
+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 (exit_code, stdout) |