run os.system commands on a new terminal- Python 3

倾然丶 夕夏残阳落幕 提交于 2019-12-13 04:00:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!