PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, August 18, 2022

[FIXED] How to interact with an exe file with python

 August 18, 2022     exe, input, output, python, subprocess     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing