I have an executable xyz.exe
that is purely driven by command prompt/shell. It interactively takes input and displays output. Assume xyz.exe
is somewhat like the typical python shell on windows. It waits for user to type something >>>
and thereby proceeds to process the input.
Now, I want to get control over this xyz.exe
process and bring it entirely into the context of my current python console/shell. How can I do this?
I referred Assign output of os.system to a variable and prevent it from being displayed on the screen and tried doing the same using subprocess:
import subprocess
cmd = r"\\sharedLocation\path\xyz.exe"
proc = subprocess.Popen([cmd], stdout=subprocess.PIPE, shell=True)
(out, err) = proc.communicate()
print("program output:", out)
but that only gets the immediate (first time) output of xyz.exe
when it starts, more like the welcome message. But after the first time output/welcome message, the xyz.exe
actually waits for user input ">>>"
... I want my current execution of the python script to wait()
and bring-in the entire context of xyz.exe
inside the scope of my script output. Is there a way to do this in python?