Created
December 16, 2011 05:06
-
-
Save sweenzor/1484573 to your computer and use it in GitHub Desktop.
Experimenting with subprocess control
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
#!/usr/bin/env python | |
import time | |
import subprocess | |
from syslog import syslog | |
def run(): | |
#cmd = ['ifconfig'] | |
cmd = ['ping', '-c', '3', 'google.com'] | |
p = subprocess.Popen(cmd, stdout=subprocess.PIPE) | |
mark = time.time() | |
while (time.time()-mark) < 200: | |
syslog(p.stdout.readline()) | |
if p.poll() is not None: | |
break | |
try: | |
p.kill() | |
print 'killed' | |
except: | |
print 'done' | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment