I am attempting something very similar to real time subprocess.Popen via stdout and PIPE
I, however, want to send input to the running process as well.
If I
The select module in the standard library is made for these kind of situation:
process = subprocess.Popen(cmd,stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
while True:
reads,writes,excs = select.select([process.stdout, process.stderr], [process.stdin], [], 1)
for r in reads:
out = r.read(1)
display.insert(INSERT, out)
sys.stdout.write(out)
sys.stdout.flush()
for w in writes:
w.write('a')
You can pass a list of file objects or file descriptors to select()
which will return those files that are have data ready for read/write or until an optional timeout.
The select module works on both Windows and Unix-like systems (Linux, Macs, etc).