Issue
I have an exe file which accepts input from the keyboard, and returns a response based on the input text. When trying to read the output returned by the exe the python script freezes.
I'm running Windows 7 and python3.7. I've tried the answer at continuously interacting with .exe file using python.
from subprocess import Popen, PIPE
location = "C:\\Users\\file.exe"
p= Popen([location],stdin=PIPE,stdout=PIPE,stderr=PIPE, encoding="UTF8")
command='START'
p.stdin.write(command)
response=p.stdout.read()
I expect response to be populated with the output text, but instead the program freezes on that line.
The exe file that I want to interact with is here (EMBRYO file)
Solution
It seems like stdout wasn't being executed since the stdin wasn't being flushed, after calling p.stdin.flush() everything worked!
from subprocess import Popen, PIPE
location = "C:\\Users\\file.exe"
p= Popen(location,stdin=PIPE,stdout=PIPE,stderr=PIPE, encoding="UTF8")
command='START\n'
p.stdin.write(command)
p.stdin.flush() # important
response=p.stdout.read()
Thanks to everyone who helped :)
Answered By - Oscar Torres Answer Checked By - Mary Flores (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.