[使用python获取Linux中的默认终端

问题描述 投票:0回答:2

我正在寻找一种使用python打开用户默认终端的方法。如何找到使用的默认终端,然后在我的python脚本中使用它以避免错误?

python python-3.x linux terminal default
2个回答
0
投票

如果您的意思是实际上打开GUI终端仿真器,那很难做到[1]。

一种可能的解决方案是为当前配置的终端仿真器调用alternatives名称。在控制台中尝试命令x-terminal-emulator,它将打开终端仿真器。

但是,可能未在所有系统中都安装。

[1] https://superuser.com/questions/1153988/find-the-default-terminal-emulator


0
投票

在Linux中,用户当前终端的信息存储在环境变量TERM]中>

您可以在我们的终端中通过echo $ TERM

进行检查。

此代码将完成工作,您要的是:-

import os  ## Importing os library

terminal=os.environ['TERM'] ## Storing the environment variable in a variable

os.system(f"{terminal} &") ## Executing the command with **&** to free up the terminal 
© www.soinside.com 2019 - 2024. All rights reserved.