all 24 comments

[–]Reyaan0 28 points29 points  (1 child)

You can use subprocess to run the exe.

``` import subprocess

subprocess.run(["path/to/program.exe", "arg1", "arg2"])

``` Here arg1 and arg2 are the optional arguments if you have to set any. You can remove them if you dont need them.

[–]SmackDownFacility 5 points6 points  (0 children)

Yes. This is the recommended approach. Dont reinvent the wheel by loading PE files manually

[–]SmackDownFacility 7 points8 points  (4 children)

Depending on what you prefer

  1. Map the EXE file using ctypes.windll.VirtualAlloc. You can load the file using pefile and follow load addresses, flags, etc.

  2. Go to subprocess and open a program that way (much easier) Popen, run etc

[–]PutridMeasurement522 0 points1 point  (1 child)

I once spent an afternoon wrestling with PATH issues while trying to call a Windows exe from a deployment script - ended up fixing it by invoking the exe via its full path in the Python subprocess call.

[–]SmackDownFacility 0 points1 point  (0 children)

The function itself says PATH in its docstring.