How do I open a program in the background and exit the script with no output text?
Question:
For example, if I run Popen(["firefox", "https://example.org/"])
, I get a message along the lines of
Gtk-Message: 21:33:04.621: Failed to load module "appmenu-gtk-module"
Is there a way to run that same Popen (or any equivalent) and have no messages printed to the screen, and then kill the program (main.py)?
Eg:
command(["firefox", "https://example.org/"])
exit(0)
Opens firefox, then automatically exits the program, leaving the command()
still active, and with no output from command()
.
Answers:
you just have to start a new detached session and null stderr and stdout
from subprocess import Popen
import subprocess
import os
process = Popen(["firefox", "https://example.org/"],
stdin=subprocess.DEVNULL, stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL,
start_new_session=True)
exit(0)
For example, if I run Popen(["firefox", "https://example.org/"])
, I get a message along the lines of
Gtk-Message: 21:33:04.621: Failed to load module "appmenu-gtk-module"
Is there a way to run that same Popen (or any equivalent) and have no messages printed to the screen, and then kill the program (main.py)?
Eg:
command(["firefox", "https://example.org/"])
exit(0)
Opens firefox, then automatically exits the program, leaving the
command()
still active, and with no output fromcommand()
.
you just have to start a new detached session and null stderr and stdout
from subprocess import Popen
import subprocess
import os
process = Popen(["firefox", "https://example.org/"],
stdin=subprocess.DEVNULL, stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL,
start_new_session=True)
exit(0)