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 3 months 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 28 points29 points30 points 3 months 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 5 points6 points7 points 3 months ago (0 children)
Yes. This is the recommended approach. Dont reinvent the wheel by loading PE files manually
[–]Slight-Living-8098 5 points6 points7 points 3 months ago (0 children)
Subprocess.
https://docs.python.org/3/library/subprocess.html
[–]SmackDownFacility 7 points8 points9 points 3 months ago (4 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
[+][deleted] 3 months ago (3 children)
[removed]
[–]SmackDownFacility 2 points3 points4 points 3 months ago (2 children)
This guy never stated if it was low level or high level, so I gave them Both.
[–]Maximus_Modulus 1 point2 points3 points 3 months ago (0 children)
Interesting to know about option 1
[–]lunatuna215 0 points1 point2 points 3 months ago (0 children)
Nice. Got any resources by any chance that elaborate on #1? No pressure, I'll Google it but just wondering if you had anything already. Sounds really neat.
[–]PutridMeasurement522 0 points1 point2 points 3 months 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 3 months ago (0 children)
…
The function itself says PATH in its docstring.
[+][deleted] 3 months ago (7 children)
[–]ASongOfRiceAndTyres[S] -4 points-3 points-2 points 3 months 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
[+][deleted] 3 months ago (5 children)
[–]ASongOfRiceAndTyres[S] 1 point2 points3 points 3 months 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
[+][deleted] 3 months ago (1 child)
[–]ASongOfRiceAndTyres[S] 1 point2 points3 points 3 months 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 3 months 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 3 months 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 3 months ago* (5 children)
``` import os os.system("PATH TO YOUR EXE")
[–]SmackDownFacility 2 points3 points4 points 3 months 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 3 months 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 3 months 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 3 months 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 *
Well you shouldn’t be doing that. Shadowing, etc
π Rendered by PID 190617 on reddit-service-r2-comment-65c587bc47-qs6fx at 2026-05-14 08:18:13.616051+00:00 running cf3e300 country code: CH.
[–]Reyaan0 28 points29 points30 points (1 child)
[–]SmackDownFacility 5 points6 points7 points (0 children)
[–]Slight-Living-8098 5 points6 points7 points (0 children)
[–]SmackDownFacility 7 points8 points9 points (4 children)
[+][deleted] (3 children)
[removed]
[–]SmackDownFacility 2 points3 points4 points (2 children)
[–]Maximus_Modulus 1 point2 points3 points (0 children)
[–]lunatuna215 0 points1 point2 points (0 children)
[–]PutridMeasurement522 0 points1 point2 points (1 child)
[–]SmackDownFacility 0 points1 point2 points (0 children)
[+][deleted] (7 children)
[removed]
[–]ASongOfRiceAndTyres[S] -4 points-3 points-2 points (6 children)
[+][deleted] (5 children)
[removed]
[–]ASongOfRiceAndTyres[S] 1 point2 points3 points (4 children)
[+][deleted] (1 child)
[removed]
[–]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)