with Popen('ngrep -iW byline'.split() + [filter_], stdout=PIPE) as process:
    with open('/path/to/file.log', 'ab') as log_file:
        for line in process.stdout:
            log_file.write(line)
How to spawn another process and capture output in python?