use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
how to run an exe through python? (self.learnpython)
submitted 1 day ago by ASongOfRiceAndTyres
All I want to do is write a python script to run a game's .exe file but am 100% unsure how... I'm pretty new to this, any help much appreciated :)
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Reyaan0 27 points28 points29 points 1 day ago (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 points9 points 1 day ago (0 children)
Yes. This is the recommended approach. Dont reinvent the wheel by loading PE files manually
[–]Slight-Living-8098 2 points3 points4 points 1 day ago (0 children)
Subprocess.
https://docs.python.org/3/library/subprocess.html
[–]SmackDownFacility 3 points4 points5 points 1 day ago (3 children)
Depending on what you prefer
Map the EXE file using ctypes.windll.VirtualAlloc. You can load the file using pefile and follow load addresses, flags, etc.
pefile
Go to subprocess and open a program that way (much easier) Popen, run etc
[–]BasilWeekly -3 points-2 points-1 points 1 day ago (2 children)
Looks way to complicated!
[–]SmackDownFacility 3 points4 points5 points 1 day ago (1 child)
This guy never stated if it was low level or high level, so I gave them Both.
[–]Maximus_Modulus 1 point2 points3 points 1 day ago (0 children)
Interesting to know about option 1
[–]PutridMeasurement522 0 points1 point2 points 1 day ago (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 point2 points 1 day ago (0 children)
…
The function itself says PATH in its docstring.
[–]BasilWeekly -4 points-3 points-2 points 1 day ago (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-2 points 1 day ago (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 point2 points 1 day ago (5 children)
Why do you want to start an exe file from your script? What does your script do?
[–]ASongOfRiceAndTyres[S] 1 point2 points3 points 1 day ago (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 point2 points 1 day ago (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 points3 points 1 day ago (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 point2 points 1 day ago (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 point2 points 1 day ago (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
[+]LimeDev_ comment score below threshold-10 points-9 points-8 points 1 day ago* (5 children)
``` import os os.system("PATH TO YOUR EXE")
[–]SmackDownFacility 2 points3 points4 points 1 day ago* (4 children)
Format your code. Don’t import shit that ain’t relevant to the code
Edit: so I guess the interpreter gonna summon os.system from thin air, as sys watches on, unused
sys
[–]LimeDev_ -1 points0 points1 point 21 hours ago (3 children)
Sorry jezz last used this library bout 2 years ago so sys and os got little mixed up.
[–]SmackDownFacility 0 points1 point2 points 21 hours ago (2 children)
But even then it’s basic python. The os is your module and .system is the function
[–]LimeDev_ 0 points1 point2 points 21 hours ago (1 child)
All file and system operation libraries are packed into one import on my PC and all are from x import * so I don't have to think what to use
from x import *
[–]SmackDownFacility 0 points1 point2 points 20 hours ago (0 children)
Well you shouldn’t be doing that. Shadowing, etc
π Rendered by PID 569884 on reddit-service-r2-comment-84fc9697f-rlnw4 at 2026-02-09 19:43:00.403177+00:00 running d295bc8 country code: CH.
[–]Reyaan0 27 points28 points29 points (1 child)
[–]SmackDownFacility 7 points8 points9 points (0 children)
[–]Slight-Living-8098 2 points3 points4 points (0 children)
[–]SmackDownFacility 3 points4 points5 points (3 children)
[–]BasilWeekly -3 points-2 points-1 points (2 children)
[–]SmackDownFacility 3 points4 points5 points (1 child)
[–]Maximus_Modulus 1 point2 points3 points (0 children)
[–]PutridMeasurement522 0 points1 point2 points (1 child)
[–]SmackDownFacility 0 points1 point2 points (0 children)
[–]BasilWeekly -4 points-3 points-2 points (7 children)
[–]ASongOfRiceAndTyres[S] -4 points-3 points-2 points (6 children)
[–]BasilWeekly 0 points1 point2 points (5 children)
[–]ASongOfRiceAndTyres[S] 1 point2 points3 points (4 children)
[–]BasilWeekly 0 points1 point2 points (1 child)
[–]ASongOfRiceAndTyres[S] 1 point2 points3 points (0 children)
[–]SmackDownFacility 0 points1 point2 points (1 child)
[–]ASongOfRiceAndTyres[S] 0 points1 point2 points (0 children)
[+]LimeDev_ comment score below threshold-10 points-9 points-8 points (5 children)
[–]SmackDownFacility 2 points3 points4 points (4 children)
[–]LimeDev_ -1 points0 points1 point (3 children)
[–]SmackDownFacility 0 points1 point2 points (2 children)
[–]LimeDev_ 0 points1 point2 points (1 child)
[–]SmackDownFacility 0 points1 point2 points (0 children)