Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save indraniel/a10424e06223365233179f8d2ccc9005 to your computer and use it in GitHub Desktop.
Save indraniel/a10424e06223365233179f8d2ccc9005 to your computer and use it in GitHub Desktop.
subprocess
p = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE)
# Grab stdout line by line as it becomes available. This will loop until
# p terminates.
while p.poll() is None:
l = p.stdout.readline() # This blocks until it receives a newline.
print l
# When the subprocess terminates there might be unconsumed output
# that still needs to be processed.
print p.stdout.read()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment