Interact with a Windows console application via Python

后端 未结 5 1357
花落未央
花落未央 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

    Have you tried to force windows end lines? i.e.

    p.stdin.write( 'command1 \r\n' )
    p.stdout.readline()
    

    UPDATE:

    I've just checked the solution on windows cmd.exe and it works with readline(). But it has one problem Popen's stdout.readline blocks. So if the app will ever return something without endline your app will stuck forever.

    But there is a work around for that check out: http://code.activestate.com/recipes/440554/

提交回复
热议问题