Skip to content

Instantly share code, notes, and snippets.

@antonchen
Created May 25, 2018 02:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antonchen/0a3c513e2b09b04e2c60b52f96ccb091 to your computer and use it in GitHub Desktop.
Save antonchen/0a3c513e2b09b04e2c60b52f96ccb091 to your computer and use it in GitHub Desktop.
from subprocess import Popen, PIPE
import json
def run_command(command):
command_process = Popen(command, stdout=PIPE, shell=True)
while True:
line = command_process.stdout.readline().rstrip()
if not line:
break
yield line
for line in run_command('tail -f file.log'):
print(json.load(line)['type'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment