Skip to content

Instantly share code, notes, and snippets.

@dejanu
Created June 27, 2019 21:47
Show Gist options
  • Save dejanu/2b65f6918ca40cb6ff8632513c44df2c to your computer and use it in GitHub Desktop.
Save dejanu/2b65f6918ca40cb6ff8632513c44df2c to your computer and use it in GitHub Desktop.
Call process and read output realtime
import subprocess
import shlex
def run_command(command):
"""command: str"""
process = subprocess.Popen(shlex.split(command), stdout=subprocess.PIPE)
while True:
output = process.stdout.readline()
if output == '' and process.poll() is not None:
break
if output:
print output.strip()
rc = process.poll()
return rc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment