Skip to content

Instantly share code, notes, and snippets.

@vdebergue
Last active August 29, 2015 14:09
Show Gist options
  • Select an option

  • Save vdebergue/c8b4abe894593873788c to your computer and use it in GitHub Desktop.

Select an option

Save vdebergue/c8b4abe894593873788c to your computer and use it in GitHub Desktop.
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