如何在可执行文件上运行脚本?

2024-10-04 03:26:22 发布

您现在位置:Python中文网/ 问答频道 /正文

也许我的问题是愚蠢的,但如果有人能帮我,我会很高兴,我有一些可执行文件,我从我的老师那里得到,这个可执行文件要求一些数学问题的答案,如果你在CMD上运行它,它看起来像:

screenshot of console window

C:\Users\guyzw>solveme.exe
Hello fellow, can you solve this math problem?

2 x 7?

>

我用wine在我的linux机器上运行这个exe文件,我想用bash或python编写一些脚本来自动插入答案,我的问题是怎么做?这个exe文件没有参数,所以我不知道从哪里开始。。。你知道吗

任何帮助都将不胜感激。你知道吗


Tags: 文件答案cmdyou可执行文件hello数学老师
2条回答

可以使用subprocess模块在Python脚本中运行外部程序。你知道吗

例如

>>> output = subprocess.Popen("solveme.exe", stdout=subprocess.PIPE)
>>> output.communicate()[0]
'hello fellow, can you solve this math problem?\n\n2 x 7?\n'
>>>

签出xdool:https://github.com/jordansissel/xdotool

它允许您在linux中创建假键盘和鼠标输入。你知道吗

相关问题 更多 >