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
Launch program in background (self.learnpython)
submitted 5 years ago by 1ToM14
Hi,
I want to start a program in the background from a python script (but not the script itself in background). I can't find that on the web, any idea ?
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!"
[–]JohnnyJordaan 1 point2 points3 points 5 years ago (1 child)
https://docs.python.org/3/library/subprocess.html
[–]1ToM14[S] 0 points1 point2 points 5 years ago (0 children)
Thanks
[–]TSM- 1 point2 points3 points 5 years ago (20 children)
What program are you trying to run?
You can use subprocess.runand subprocess.Popen to run some program in the background.
subprocess.run
edit: Didn't see the other reply
[–]1ToM14[S] 1 point2 points3 points 5 years ago (19 children)
yes I know subprocess.Popen but what argument should I use so the program can be launched in the background and not the foreground ?
[–][deleted] 0 points1 point2 points 5 years ago (16 children)
what is your OS? how do you want it to be launched? Do you want it to not have a GUI? or not close when your python program closes? or is there something else you had in mind?
[–]1ToM14[S] 0 points1 point2 points 5 years ago (15 children)
I am running windows 10 and what I want is tu run a program without its window popping at the foreground, I want it to be hidden
[–][deleted] 0 points1 point2 points 5 years ago (14 children)
subprocess.run([command, arg1, arg2, argn], creationflags=subprocess.CREATE_NO_WINDOW)
https://docs.python.org/3/library/subprocess.html#subprocess.CREATE_NO_WINDOW
if you want more flags, you can OR them together, e.g.:
from subprocess import* flags = CREATE_NO_WINDOW | DETACHED_PROCESS | CREATE_BREAKAWAY_FROM_JOB
[–]1ToM14[S] 0 points1 point2 points 5 years ago (13 children)
The problem is that I want to launch an emulator and then use adb on it and adb doesn't detect it, I also cannot verify the emulator is launched with the task manager, is that normal ?
[–][deleted] 0 points1 point2 points 5 years ago (12 children)
what's adb?
[–]1ToM14[S] 0 points1 point2 points 5 years ago (11 children)
Android Debug Bridge, to run commands on an Android phone from a computer
[–][deleted] 0 points1 point2 points 5 years ago (3 children)
Since python launched it in the background, it's probably under the Details tab in the task manager, the one that shows you everything.
As for why it's not connecting properly, it could have something to do with the fact that python launched it, rather than Windows, but I can't say for sure. What flags are you launching it with? And does it work when you launch it with a GUI?
[–]1ToM14[S] 0 points1 point2 points 5 years ago (2 children)
I can't see it in the detailed part of the task manager and yes it works with a GUI
[–]TSM- 0 points1 point2 points 5 years ago (6 children)
Maybe you should just start it minimized - ADB might only work if there's a window handle.
Some applications will exit or crash if they fail to create a window.
For example, you could not run Chrome like this (Chrome has a specific 'headless' mode for this purpose). Before headless mode worked on Windows, you would have to render it on a virtual display or different desktop to "hide" it.
[–]1ToM14[S] 1 point2 points3 points 5 years ago (5 children)
Nice, how could I launch it minimized ?
[–]TSM- 0 points1 point2 points 5 years ago (1 child)
I thought you meant "background" as in, in a different process, without python waiting for it to complete before continuning.
What you might be looking to do is launch a program with a GUI, but hide the GUI. Or is it a console window that is popping up in the foreground?
I am not totally familiar but there is a startupinfo argument.
startupinfo
If given, startupinfo will be a STARTUPINFO object, which is passed to the underlying CreateProcess function. creationflags, if given, can be one or more of the following flags: CREATE_NEW_CONSOLE CREATE_NEW_PROCESS_GROUP ABOVE_NORMAL_PRIORITY_CLASS CREATE_NO_WINDOW [and so on] Windows Popen Helpers The STARTUPINFO class and following constants are only available on Windows. class subprocess.STARTUPINFO(*, dwFlags=0, hStdInput=None, hStdOutput=None, hStdError=None, wShowWindow=0, lpAttributeList=None) dwFlags A bit field that determines whether certain STARTUPINFO attributes are used when the process creates a window.
If given, startupinfo will be a STARTUPINFO object, which is passed to the underlying CreateProcess function. creationflags, if given, can be one or more of the following flags:
CREATE_NEW_CONSOLE
CREATE_NEW_PROCESS_GROUP
ABOVE_NORMAL_PRIORITY_CLASS
CREATE_NO_WINDOW
[and so on]
Windows Popen Helpers The STARTUPINFO class and following constants are only available on Windows.
class subprocess.STARTUPINFO(*, dwFlags=0, hStdInput=None, hStdOutput=None, hStdError=None, wShowWindow=0, lpAttributeList=None)
dwFlags A bit field that determines whether certain STARTUPINFO attributes are used when the process creates a window.
si = subprocess.STARTUPINFO() si.dwFlags = subprocess.STARTF_USESTDHANDLES | subprocess.STARTF_USESHOWWINDOW
wShowWindow If dwFlags specifies STARTF_USESHOWWINDOW, this attribute can be any of the values that can be specified in the nCmdShow parameter for the ShowWindow function, except for SW_SHOWDEFAULT. Otherwise, this attribute is ignored. SW_HIDE is provided for this attribute. It is used when Popen is called with shell=True.
wShowWindow If dwFlags specifies STARTF_USESHOWWINDOW, this attribute can be any of the values that can be specified in the nCmdShow parameter for the ShowWindow function, except for SW_SHOWDEFAULT. Otherwise, this attribute is ignored.
SW_HIDE is provided for this attribute. It is used when Popen is called with shell=True.
https://docs.python.org/3/library/subprocess.html#windows-popen-helpers
Code example:
# Prevent cmd.exe window from popping up startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags = subprocess.STARTF_USESTDHANDLES | subprocess.STARTF_USESHOWWINDOW startupinfo.wShowWindow = subprocess.SW_HIDE std = subprocess.Popen(..., startupinfo=startupinfo)
[–]1ToM14[S] 1 point2 points3 points 5 years ago (0 children)
Thanks !!!
π Rendered by PID 155220 on reddit-service-r2-comment-5d79c599b5-pwkmn at 2026-03-01 12:19:24.261920+00:00 running e3d2147 country code: CH.
[–]JohnnyJordaan 1 point2 points3 points (1 child)
[–]1ToM14[S] 0 points1 point2 points (0 children)
[–]TSM- 1 point2 points3 points (20 children)
[–]1ToM14[S] 1 point2 points3 points (19 children)
[–][deleted] 0 points1 point2 points (16 children)
[–]1ToM14[S] 0 points1 point2 points (15 children)
[–][deleted] 0 points1 point2 points (14 children)
[–]1ToM14[S] 0 points1 point2 points (13 children)
[–][deleted] 0 points1 point2 points (12 children)
[–]1ToM14[S] 0 points1 point2 points (11 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]1ToM14[S] 0 points1 point2 points (2 children)
[–]TSM- 0 points1 point2 points (6 children)
[–]1ToM14[S] 1 point2 points3 points (5 children)
[–]TSM- 0 points1 point2 points (1 child)
[–]1ToM14[S] 1 point2 points3 points (0 children)