0

In the code below I am trying to create certain groups of apps I can start through typing a certain number in the input field. The problem I am facing is that the apps (in this case Firefox) are closing after the python script is finished with executing. Is there a way to start an .exe file without the program exiting together with the script?

import subprocess

app_group_choice = int(input('Enter app group to open: '))

def Apps_school():
    subprocess.call(r"C:\Program Files\Mozilla Firefox\firefox.exe")
    print("Ok")

if app_group_choice == 1:
    Apps_school()
Jan
  • 31
  • 4
  • Does this answer your question? [Do NOT terminate python subprocess when script ends](https://stackoverflow.com/questions/25127561/do-not-terminate-python-subprocess-when-script-ends) – Random Davis Apr 23 '21 at 22:07

2 Answers2

0

I could not reproduce the same error. What OS are you using? When I ran the provided code, Firefox remained open after the program ended.

However, it appears that subprocess.Popen() might be the right function to use for this application. It opens the app in a new process and then continues with the code but the lifetime of the app (e.g. Firefox) is not dependent on the script that called it. (https://docs.python.org/3/library/subprocess.html#subprocess.Popen)

0

Ok, so apparently I had this problem only when I was running my python script from the terminal inside VSCode which maybe had parameters that led to Firefox not staying open. When I ran it straight from cmd or by double clicking It worked perfectly fine.

Jan
  • 31
  • 4