From 3343f56b770aa0a56c4ae12143796b122acdeb76 Mon Sep 17 00:00:00 2001 From: Don Garrett Date: Fri, 21 Jan 2011 16:06:51 -0800 Subject: [PATCH] Add a verbose option to RunCommandCaptureOutput. Not used yet, does not dump output until after the command has finished, so not useful for following 'live'. Change-Id: Ia8562f5e6f8d7ed8af7e188faa68f5cdbba487c6 BUG=chromium-os:11164 TEST=None Review URL: http://codereview.chromium.org/6296013 --- lib/cros_build_lib.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/cros_build_lib.py b/lib/cros_build_lib.py index ec7c028167..22f7de946e 100644 --- a/lib/cros_build_lib.py +++ b/lib/cros_build_lib.py @@ -95,7 +95,8 @@ def RunCommand(cmd, print_cmd=True, error_ok=False, error_message=None, def RunCommandCaptureOutput(cmd, print_cmd=True, cwd=None, input=None, enter_chroot=False, - combine_stdout_stderr=True): + combine_stdout_stderr=True, + verbose=False): """Runs a shell command. Differs from RunCommand, because it allows you to run a command and capture the exit code, output, and stderr all at the same time. @@ -109,6 +110,7 @@ def RunCommandCaptureOutput(cmd, print_cmd=True, cwd=None, input=None, enter_chroot: this command should be run from within the chroot. If set, cwd must point to the scripts directory. combine_stdout_stderr -- combine outputs together. + verbose -- also echo cmd.stdout and cmd.stderr to stdout and stderr Returns: Returns a tuple: (exit_code, stdout, stderr) (integer, string, string) @@ -132,7 +134,11 @@ def RunCommandCaptureOutput(cmd, print_cmd=True, cwd=None, input=None, proc = subprocess.Popen(cmd, cwd=cwd, stdin=stdin, stdout=stdout, stderr=stderr) - (output, error) = proc.communicate(input) + output, error = proc.communicate(input) + + if verbose: + if output: sys.stdout.write(output) + if error: sys.stderr.write(error) # Error is None if stdout, stderr are combined. return proc.returncode, output, error