Python subprocess: Print to stdin, read stdout until newline, repeat

Viewed 926

I am looking to interface with an interactive command line application using Python 3.5. The idea is that I start the process at the beginning of the Python script and leave it open. In a loop, I print a file path, followed by a line return, to stdin, wait for a quarter second or so as it processes, and read from stdout until it reaches a newline.

This is quite similar to the communicate feature of subprocess, but I am waiting for a line return instead of waiting for the process to terminate. Anyone aware of a relatively simple way to do this?

Edit: it would be preferable to use the standard library to do this, rather than third-party libraries such as pexpect, if possible.

2 Answers
Related