Since you're on Windows, you can call the start
command, which exists for this very purpose: to run another program independently of the one that starts it.
The start
command is provided by the command-line interpreter cmd.exe
. It is not an executable: there is no start.exe
. It is a "shell command" (in Linux terminology), which is why shell=True
must be passed when creating the subprocess.
You won't be able to communicate with the subprocess started in this way, that is, not via the pipe mechanism provided by the subprocess
module. So instead of Popen
, you may just use the convenience function run
:
from subprocess import run
app = 'notepad'
run(['start', app], shell=True)
The example starts the Notepad editor (instead of Discord in the question) in order to make it easier to reproduce.
In cases where the full path to the app
contains spaces, we can either call start
like so
app = r'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe'
run(f'start "" "{app}"', shell=True)
using the Edge browser in this example, or pass the directory separately:
folder = r'C:\Program Files (x86)\Microsoft\Edge\Application'
app = 'msedge.exe'
run(['start', '/d', folder, app], shell=True)
This is needed because start
treats a single argument as the window title if that argument is in quotes. And only if not does it treat it as the command. See "Can I use the start
command with spaces in the path?" (on SuperUser) for more details.