0

maybe my question is stupid but I would be very happy if someone could help, I have some executable file that I got from my teacher, this executable file ask for the answer of some math problem and if you run it on CMD it's look like:

screenshot of console window

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

2 x 7?

>

I'm run this exe file on my linux machine using wine, I want to write some of script in bash or python to insert the answer automatically, my question is how can I do so? this exe file doesn't get args so I don't now where to begin...

Any help would be appreciated.

melpomene
  • 84,125
  • 8
  • 85
  • 148
gaidediz
  • 59
  • 7

2 Answers2

1

You can use the subprocess module to run external programs from within a Python script.

For example,

>>> output = subprocess.Popen("solveme.exe", stdout=subprocess.PIPE)
>>> output.communicate()[0]
'hello fellow, can you solve this math problem?\n\n2 x 7?\n'
>>>
  • I think that in this case you need to call `wine` with `args=[/path/to/solveme.exe]` – R2RT Jun 10 '18 at 08:33
  • Ahh, I concur! Thanks for the heads up. Here's a [post](https://stackoverflow.com/a/47868895/9920493) elaborating on R2RT's comment. – kimplausibl0 Jun 10 '18 at 08:39
  • @ kimplausibl0 - if I doing so, I got some empty lines without 'hello fellow, can you solve this math problem?\n\n2 x 7?\n' ... what I miss? – gaidediz Jun 13 '18 at 19:33
0

Checkout xdotool: https://github.com/jordansissel/xdotool

It allows you to create fake keyboard and mouse input in linux.

Andreas Hartmann
  • 1,825
  • 4
  • 23
  • 36