Skip to content

Instantly share code, notes, and snippets.

@Kwpolska
Created January 7, 2016 19:11
Show Gist options
  • Select an option

  • Save Kwpolska/f9cda61951dc7dad4c79 to your computer and use it in GitHub Desktop.

Select an option

Save Kwpolska/f9cda61951dc7dad4c79 to your computer and use it in GitHub Desktop.
import subprocess
import time
p = subprocess.Popen(['error-prone', 'thing'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
while p.poll() is None:
time.sleep(0.5) # prevent 100% CPU usage
if p.returncode != 0:
stdout, stderr = p.communicate()
print("The process failed with code {0}.\nstdout:\n{1}\nstderr:\n{2}".format(p.returncode, stdout, stderr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment