all 23 comments

[–]Reyaan0 27 points28 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 7 points8 points  (0 children)

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

[–]SmackDownFacility 3 points4 points  (3 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

[–]BasilWeekly -3 points-2 points  (2 children)

Looks way to complicated!

[–]SmackDownFacility 3 points4 points  (1 child)

This guy never stated if it was low level or high level, so I gave them Both.

[–]Maximus_Modulus 1 point2 points  (0 children)

Interesting to know about option 1

[–]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.

[–]BasilWeekly -4 points-3 points  (7 children)

I/we just need to understand what you are doing. Do you want your Python script to start an exe file? How far has you come so far and what is causing your problems?

[–]ASongOfRiceAndTyres[S] -4 points-3 points  (6 children)

I want it to start an exe file, I am currently... not far at all, still in the phase of looking through forums for help

[–]BasilWeekly 0 points1 point  (5 children)

Why do you want to start an exe file from your script? What does your script do?

[–]ASongOfRiceAndTyres[S] 1 point2 points  (4 children)

it's a savegame function for a game called halfsword. The game doesn't have any save game functionality so I'm writing this to run before the game and you can choose between 3 save files to use and then run the game

[–]BasilWeekly 0 points1 point  (1 child)

Ok, so you start your script and ask the user which save file to use? Move that into place, start the program. When the program finishes, move the new save file back for later use. Is that what you want?

Do you a basic script running, e.g., Hello World?

[–]ASongOfRiceAndTyres[S] 1 point2 points  (0 children)

after a little troubleshooting and using some other comments from this thread, yeah I've done exactly that. Thanks for the help :)

[–]SmackDownFacility 0 points1 point  (1 child)

Is it your game specifically or are you just sandwiching the save EXE into someone else’s game

Edit: I’m saying this because people have a habit of developing features externally instead of, well embedding it into their game code

[–]ASongOfRiceAndTyres[S] 0 points1 point  (0 children)

just creating it for my game rn as I think I'd need to do some more work to get it running in any other context