Created
June 27, 2019 21:47
-
-
Save dejanu/2b65f6918ca40cb6ff8632513c44df2c to your computer and use it in GitHub Desktop.
Call process and read output realtime
This file contains 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
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