Problem statement
What I want to do is run a program with a CLI. this program accepts one command at a time and execute it.(lets say cmd.exe) Most the time these commands goes in batches. So feeding a list of command at ones on one stream is going to work great but I also want to intervene manually time to time by sending some additional commands through the keyboard.
Initial attempt
I tried using CREATE_NEW_CONSOLE so that a new command window pops up as below.
from subprocess import Popen, PIPE, CREATE_NEW_CONSOLE
x = Popen('cmd.exe', creationflags=CREATE_NEW_CONSOLE)
So this allows me to feed commands manually and that part is ok. Now the question is how can I feed the same program some commands through x
My attempts to resolve it
- I tried giving stdin=PIPE but in that case python does not create a new console.
- I tried x.communicate(input='dir') for example but nothing appeared on the console or python prompt.
- Tried to use os.mkfifo but this is depreciated.
Question
Is there a way to get this done using subprocess or some other means(possibly tempfile?). I am not interested on taking the output from the process for now.