无法使用 python 子进程在 ubuntu 上调用 gnome 终端
Not able to invoke gnome-terminal on ubuntu with python subprocess
用例:
我需要 运行 在两个单独的 gnome 终端上执行命令。
command 是 'appium -p port' ,其中 port 是一个包含两个端口号的列表。
所以最后的命令就像
appium -p 4723
appium -p 4750
这是我的代码
import os
import signal
import subprocess
def open_ubuntu_appium(*args):
for item in args:
for subitem in item:
subitem=str(subitem)
command='appium -p'
command ='"'+command+' '+subitem+';read -n1" '
print command
#"appium -p 4723;read -n1"
#"appium -p 4750;read -n1"
subitem = Popen(['gnome-terminal','--disable-factory','-x','bash','-c',command],preexec_fn=os.setpgrp)
port=[4723,4750]
appium=open_ubuntu_appium(port)
输出:
没有调用 gnome 终端
预期:
两个独立的 Gnome 终端应该使用命令
调用
appium -p 4723
appium -p 4750
我在这里做错了什么,有没有其他方法可以做到这一点。
我还需要在启动后终止调用的终端
我仍然无法解决上述问题,但是我在 ubuntu
中找到了打开多个终端的替代方法
from subprocess import Popen
def open_appium(*args):
command='appium -p'
linux_terminal=['gnome-terminal']
for item in args:
for port in item:
linux_terminal.extend((['--tab','--disable-factory','-e', '''
bash -c '
echo "%(command)s %(port)s"
%(command)s "%(port)s"
read
'
''' % locals()]))
linux_window=Popen(terminal,preexec_fn=os.setpgrp)
port=[4723,4730]
ab=open_appium(port)
输出:
"appium -p" + port 命令
将调用两个单独的 gnome 终端
用例: 我需要 运行 在两个单独的 gnome 终端上执行命令。
command 是 'appium -p port' ,其中 port 是一个包含两个端口号的列表。 所以最后的命令就像
appium -p 4723
appium -p 4750
这是我的代码
import os
import signal
import subprocess
def open_ubuntu_appium(*args):
for item in args:
for subitem in item:
subitem=str(subitem)
command='appium -p'
command ='"'+command+' '+subitem+';read -n1" '
print command
#"appium -p 4723;read -n1"
#"appium -p 4750;read -n1"
subitem = Popen(['gnome-terminal','--disable-factory','-x','bash','-c',command],preexec_fn=os.setpgrp)
port=[4723,4750]
appium=open_ubuntu_appium(port)
输出: 没有调用 gnome 终端
预期: 两个独立的 Gnome 终端应该使用命令
调用appium -p 4723
appium -p 4750
我在这里做错了什么,有没有其他方法可以做到这一点。 我还需要在启动后终止调用的终端
我仍然无法解决上述问题,但是我在 ubuntu
中找到了打开多个终端的替代方法 from subprocess import Popen
def open_appium(*args):
command='appium -p'
linux_terminal=['gnome-terminal']
for item in args:
for port in item:
linux_terminal.extend((['--tab','--disable-factory','-e', '''
bash -c '
echo "%(command)s %(port)s"
%(command)s "%(port)s"
read
'
''' % locals()]))
linux_window=Popen(terminal,preexec_fn=os.setpgrp)
port=[4723,4730]
ab=open_appium(port)
输出: "appium -p" + port 命令
将调用两个单独的 gnome 终端