问题
I am running a program which allows me to run terminal commands through my Python code which takes input from the user through the command line. This is the part of the code where I open Google-Chrome
import sys
import os
os.system("google-chrome") #I have Ubuntu 16.04
It opens the browser but the problem is that the terminal on which my python code is running becomes the same as the one where Chrome is running which means that I cannot give further input to my Python code. To solve this problem I need the Chrome to run as a process on a different terminal. I tried using subprocess.call("google-chrome", shell=True)
but it did not open it on a new terminal.
How do I make the process run on a different terminal?
回答1:
can this solve your problem?
os.system('gnome-terminal -x chromium-browser')
回答2:
Use subprocess.popen("command")
Basically, run the subprocess in the background. & is a shell feature. Use popen instead
来源:https://stackoverflow.com/questions/50344490/run-os-system-commands-on-a-new-terminal-python-3