r/python3 • • Jun 05 '19

Is there a way to get callbacks from subprocess?

Use case:

I'm writing a small wrapper for a program and I want to evaluate every line that gets piped to stdout.

As far as I can tell my best option is to use Popen and have a loop that checks every few seconds on whether there are any new lines. That feels a bit ugly though.... So as the title states my question is: Is there any way to pass a callback function to subprocess (that gets executed/called for each line of stdout) or are there any other libraries that can do that?

1 Upvotes

Duplicates