1

I've seen questions about python launching a windows EXE file, but I need something a little different... I'd like to do it on a machine running Ubuntu.

I have a windows EXE which opens a window, allows me to choose a COM port and enter a filename, and then has a couple of buttons with which I can query a sensor on that COM port and write the output to a file. I need to automate this data gathering process, and would love to simply mimic the EXE's behavior with a python script on my MinnowBoard running Ubuntu 16.04 LTS, but the creator of the sensor won't share the protocol they use to talk to their sensor. The obvious protocols don't seem to work, so I'm left with their compiled executable.

Is there a way, in python on linux, to run the Windows executable, enter text into the filename field, and click some buttons in a particular sequence? Essentially, I'm looking for a generalized macro functionality INSIDE an emulator (like Wine?). The EXE can be operated via keypresses (a mouse isn't essential), if that makes a difference. Any thoughts would be helpful!

Mark
  • 21
  • 4
  • Btw, googling for *python automate windows* first hit: https://pywinauto.github.io/ – MB-F Feb 23 '17 at 13:56

1 Answers1

0

At first checkout system, it calls the passed string as a commandline. Here an example to edit a file in the windows-notepad.

from os import system
print("input path and filename to open a file")
print("input nothing to create a new file")
file = input(">>> ")
system("notepad.exe {}".format(file))

Windows-programs also have switches (marked with / or - before a letter) to change the behavior. Check out -? on some windows-programs to get more specific information in the commandline.

On linux, you should install a virtual-machine. Call the vm with system, where you passed the exe like the filename passed above to notepad.exe.

#windowsCommandLine is the windows programfile and its parameters -> so it is the string you will pass directly to system on windows.
system("{} {}".format(virtualBoxPath, windowsCommandLine)

With some research you could find vms, which could simulate inputs, it may be using another programming-language. In the windows-C-library are also some functions which could emulate keyboard-input.

cmdLP
  • 1,658
  • 9
  • 19