Catching Terminal Output in Python
问题 I want to do something similar to the second answer here (but not quite similar): Simulate Ctrl-C keyboard interrupt in Python while working in Linux It's much simpler and I think I'm just missing something. Say, from a python script, I just want to call 'ping' and terminate it after the 10th time. I'm trying to do it like from the link above: p = subprocess.Popen(['ping', 'google.com'], stdout=subprocess.PIPE) for line in p.stdout: print line if re.search('10', line): break os.kill(p.pid,