Communicate Multiple Times With A Subprocess In Python
This question is NOT a duplicate of Communicate multiple times with a process without breaking the pipe? That question is solved because its use case allows inputs to be sent toge
Solution 1:
Basicly Non-blocking read on a subprocess.PIPE in python
Set the proc pipes (proc.stdout, proc.stdin, ...) to nonblocking mode via fnctl
and then write/read them directly.
You might want to use epoll or select via the select
or io
modules for more efficiency.
Solution 2:
This turns out to be not very difficult:
proc = subprocess.Popen(['bc'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
os.write(proc.stdin.fileno(), b'100+200\n')
print(os.read(proc.stdout.fileno(), 4096))
Post a Comment for "Communicate Multiple Times With A Subprocess In Python"