press enter via python script

陌路散爱 提交于 2019-12-06 23:13:36
ZorleQ

Not entirely sure how to do it in python, but my suggestion would be simulate an actual 'enter' key press command. In your code, you are just changing caret's position and not issuing a proper return.

Have a look at this: http://win32com.goermezer.de/content/view/136/254/

import win32com.client
shell = win32com.client.Dispatch("WScript.Shell")
shell.SendKeys("{ENTER}", 0) 

Seems like that's exactly what you need.

The following may work (untested):

import subprocess
import win32console

APP_BIN = 'app.exe'

def main():
    proc = subprocess.Popen([APP_BIN,'-i','console'],stdin=subprocess.PIPE,
                                                     stdout=subprocess.PIPE)
    stdoutdata, stderrdata = proc.communicate(input="\r\n")
    output = stdoutdata.readline()
    print output
    ret = proc.wait()
    print ret

if __name__ == '__main__':
    main()
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!