在新终端上运行os.system命令-Python 3 [英] run os.system commands on a new terminal- Python 3
问题描述
我正在运行一个程序,该程序允许我通过Python代码运行终端命令,该代码从用户通过命令行输入.这是我打开Google-Chrome浏览器的代码的一部分
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
它会打开浏览器,但问题是运行我的python代码的终端与运行Chrome的终端相同,这意味着我无法进一步输入我的Python代码.要解决此问题,我需要将Chrome作为进程在其他终端上运行.我尝试使用subprocess.call("google-chrome", shell=True)
,但是它没有在新终端上打开它.
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?
推荐答案
这可以解决您的问题吗?
can this solve your problem?
os.system('gnome-terminal -x chromium-browser')
这篇关于在新终端上运行os.system命令-Python 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!