All of the examples I see for interacting with a process using Python 3's subprocess.Popen
use Popen.communicate("input_text")
exactly once before calling Popen.communicate()
to grab the standard output and ending the program. I have a few programs that I want to script that require human intervention via stdin, so I want to automate them since the prompts are predictable.
For example, an in-house licensing application requires us to pass the application information via prompts (not from the command line) relating to the customer's unique ID (4 digit integer), the number of users, etc. And then it has to be done 30 times (random number), each one for a different product, identified by another integer.
Scripting that is easy if only I can learn how to do a sustained back-and-forth using Popen
. Should I be using Popen.communicate()
or should I be using Popen.stdout
and Popen.stdin()
and what's the difference between both?