Created
December 3, 2018 16:01
-
-
Save agmangas/fb12f2621c54ca7d5ac6fd3cfd6511bf to your computer and use it in GitHub Desktop.
Popen.communicate() wrapper function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from subprocess import Popen, PIPE | |
def _popen_communicate(cmd_args): | |
"""Takes a list of arguments and executes a command. | |
Blocks waiting for the execution to finish. | |
Returns a tuple containing the stdout and stderr.""" | |
process = Popen(cmd_args, stdout=PIPE, stderr=PIPE) | |
stdout, stderr = process.communicate() | |
if process.returncode != 0: | |
raise Exception("'{}' returned error code: {}".format(' '.join(cmd_args), process.returncode)) | |
return stdout, stderr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment