xterm -e - 命令后不要关闭 xterm

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

我用 python 编写了 scirpt,它使用

system.os("cmd")
执行 bash 命令。我不希望在与 python 脚本输出相同的终端上输出 bash 脚本,因此我通过
xterm -e
执行 bash 命令。我的代码与此类似:

# python
import os
os.system("xterm -e 'ls'")

此代码有效,但在

ls
结束后,新终端消失。我想留在这个航站楼。

python bash xterm
3个回答
1
投票

您可以让窗口保持不变,直到用户按下

read
的按键:

os.system("xterm -e 'ls; read'")

或者您只需运行

xterm
的新终端,该终端将一直运行直到关闭:

os.system("xterm")

注 1

os.system
函数似乎会阻止 python 脚本,直到外部进程(在本例中为 xterm)完成。因此,您可以在循环中使用它,其中每个 bash 窗口必须在打开新窗口之前关闭。

注2:python文档建议使用

subprocess.call


0
投票

以下应该有效。我在 Mint linux 盒子上尝试过。

import os
os.system("xterm -hold -e 'ls' &")

0
投票

几乎不错,但是:

import os
os.system("xterm -hold -e 'my_cmd_1' &") 
os.system("xterm -hold -e 'my_cmd_2' &")

my_cmd_2 无法在 my_cmd_end_1 之前启动

© www.soinside.com 2019 - 2024. All rights reserved.