Created
December 15, 2016 21:01
-
-
Save isaaguilar/89bf5c881209a66698c69a7197befd2a to your computer and use it in GitHub Desktop.
tail -f for python
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, re | |
def tail_and_quit(filename, regex_to_match): | |
try: | |
f = subprocess.Popen(['tail', '-F', filename], stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
while True: | |
line = f.stdout.readline() | |
match = re.search(regex_to_match, line) | |
if match: break | |
finally: f.kill() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment