Skip to content

Instantly share code, notes, and snippets.

@kirillsulim
Created April 16, 2019 17:48
Show Gist options
  • Save kirillsulim/04e0bec59a598d8d10f93b34160bef56 to your computer and use it in GitHub Desktop.
Save kirillsulim/04e0bec59a598d8d10f93b34160bef56 to your computer and use it in GitHub Desktop.
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