From 40f058957e72e82f4e54d2f453c02e51c62f37c5 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Tue, 23 Dec 2014 10:29:12 -0600 Subject: Fix subprocess handling in batch-stabilize --- batch-stabilize.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/batch-stabilize.py b/batch-stabilize.py index 155af38..81f97ba 100755 --- a/batch-stabilize.py +++ b/batch-stabilize.py @@ -26,19 +26,23 @@ def print_and_log(message, log): log.flush() def run_command(args, cwd, log): - try: - message = "Running %r in %s...\n" % (args, cwd) - sys.stdout.write(message) - log.write(message) + message = "Running %r in %s...\n" % (args, cwd) + returncode = 0 + sys.stdout.write(message) + log.write(message) - cmd = subprocess.Popen(args, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - output = cmd.communicate()[0] - log.write("Finished with exit code %d\n" % cmd.returncode) - log.write(output) - return (cmd.returncode, output) + try: + output = subprocess.check_output(args, cwd=cwd, + stderr=subprocess.STDOUT, universal_newlines=True) + except subprocess.CalledProcessError as e: + output = e.output + returncode = e.returncode finally: + log.write("Finished with exit code %d\n" % returncode) + log.write(output) log.flush() + return (returncode, output) def save_state(done_bugs): with open('batch-stabilize.state', 'wb') as state_file: pickle.dump(done_bugs, state_file) -- cgit v1.2.3-65-gdbad