Interact with a Windows console application via Python

后端 未结 5 1350
花落未央
花落未央 2020-12-03 02:17

I am using python 2.5 on Windows. I wish to interact with a console process via Popen. I currently have this small snippet of code:

p = Popen( [\"console_app         


        
5条回答
  •  醉梦人生
    2020-12-03 02:40

    Is it possible that the console app is buffering its output in some way so that it is only being sent to stdout when the pipe is closed? If you have access to the code for the console app, maybe sticking a flush after a batch of output data might help?

    Alternatively, is it actually writing to stderr and instead of stdout for some reason?

    Just looked at your code again and thought of something else, I see you're sending in "command\n". Could the console app be simply waiting for a carriage return character instead of a new line? Maybe the console app is waiting for you to submit the command before it produces any output.

提交回复
热议问题