How does one open the command prompt
and then send commands to the already open console window from a python script.
I have already tried the following
+subprocess.Popen([‘cmd’,‘some command’],cwd=…)
The above line only opens the cmd window but does not pass the second command in the list to cmd.exe.
os.exec produces the same results as subprocess.Popen(…)
os = windows 7
Thanks any or solutions will be greatly appreciated
You need to create the Popen process and specify that it will read stdin from a Pipe in the Python process. You can then send whatever you want using the communicate() method.
import subprocess
process = subprocess.Popen('cmd', stdin=subprocess.PIPE)
# Note that you have to send bytes by putting a <b> before the string
process.communicate(b'echo Hello World!
')
Side note: This question doesn’t really have anything to do with the BGE and would be more suited to some other programming forum or help site such as Stack Overflow.
@Mobious
Thanks
The code does not accomplish the task the cmd window closes before I can see the result .
using os.system(“pause”) displayed a blank window, the trick with the input function was also fruitless