p = subprocess.Popen(['ping', 'google.com'], stdout=subprocess.PIPE)
while True:
    line = p.stdout.readline()
sys.stdout.write(line)
sys.stdout.flush()
if '10' in line:
    break
p.kill()
Catching Terminal Output in Python