diff options
author | 2014-12-23 10:29:12 -0600 | |
---|---|---|
committer | 2014-12-29 15:57:12 +0100 | |
commit | 40f058957e72e82f4e54d2f453c02e51c62f37c5 (patch) | |
tree | 26f8175763f21fdffbcf7f900224a4a1ceff49fc | |
parent | Port most tools to python 3 (diff) | |
download | arch-tools-40f058957e72e82f4e54d2f453c02e51c62f37c5.tar.gz arch-tools-40f058957e72e82f4e54d2f453c02e51c62f37c5.tar.bz2 arch-tools-40f058957e72e82f4e54d2f453c02e51c62f37c5.zip |
Fix subprocess handling in batch-stabilize
-rwxr-xr-x | batch-stabilize.py | 22 |
1 files 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) |