communicate
's documentation says:
Interact with process: Send data to stdin. Read data from stdout and stderr, until end-of-file is reached. Wait for process to terminate.
What do you do if you need to send input to a process more than once ? For example, I spawn a process, send it some data, the process does something with that, returns some output, and then I have to send input again? How do I handle that?
Then you can't use .communicate()
. You can either poll the streams, use select
or some other way that allows you to listen to FD changes (both gtk and Qt have tools for that, for example).
Take a look at Doug Hellman's Python Module of the Week writeup about subprocess. Search down until you see "repeater.py".
There you will find an example of how to send and receive input/output to a process.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With