Last active
August 29, 2015 14:09
-
-
Save vdebergue/c8b4abe894593873788c to your computer and use it in GitHub Desktop.
This file contains hidden or 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 atexit | |
| proc = subprocess.Popen("ping google.com", shell = True, stdout = subprocess.PIPE, stderr = subprocess.STDOUT) | |
| # register terminate function if python script is killed | |
| atexit.register(proc.terminate) | |
| for line in iter(proc.stdout.readline, ""): | |
| print "got line: '%s'" % line | |
| # setup the proc return code | |
| proc.poll() | |
| #while proc.poll() is None: | |
| # print "waiting" | |
| # nextline = proc.stdout.readline() | |
| # if nextline != "": | |
| # print nextline | |
| print "process with pid %s is finished with return code %s" % (proc.pid, proc.returncode) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment