Created
April 16, 2019 17:48
-
-
Save kirillsulim/04e0bec59a598d8d10f93b34160bef56 to your computer and use it in GitHub Desktop.
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 typing import List | |
import subprocess | |
import sys | |
def call_and_get_out(command: List[str]): | |
with subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) as p: | |
try: | |
out, err = p.communicate() | |
code = p.poll() | |
except: | |
p.kill() | |
p.wait() | |
raise | |
return code, out.decode(sys.stdout.encoding), err.decode(sys.stderr.encoding) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment