Popen and stdin to automate input to .exe
Question: I have a simple windows executable that asks for user input and I'm trying to
make a python script to automate the input. What I've done:

    
    
    from subprocess import Popen, PIPE
    p = Popen([r'myprgm.exe'], stdin=PIPE)
    p.communicate(input=bytes(input("Test Input"), 'UTF-8'))
    

Now, normally when the program runs, it outputs to the command prompt "give me
input:" then expects input from the user.

If I use Popen with the `stdin=PIPE` option, nothing is written to the command
prompt at all - it just sits there blank.

Then, when I use communicate, "Test Input" ends up on the python console, and
not to the process.

Is it possible to automate something like this? Or am I missing something
fundamental here..


Answer: You can give `input` to
[`communicate`](https://docs.python.org/2/library/subprocess.html#subprocess.Popen.communicate)
function.

like

    
    
    p1 = Popen(["mycmd"], stdin=PIPE, stdout=PIPE)
    output = p1.communicate(input="my input")[0]
    

