我正在尝试制作一个PyGtk GUI,其中包含一个按钮。 当用户按下此按钮时,gnome-terminal
提示用户输入其密码。
然后,它将克隆这个Git仓库以获取gedit
JQuery片段。
然后,将js.xml
文件复制到/usr/share/gedit/plugins/snippets/js.xml
。
最后,强制删除Git仓库。
命令:
gnome-terminal -x sudo git clone git://github.com/pererinha/gedit-snippet-jquery.git && sudo cp -f gedit-snippet-jquery/js.xml /usr/share/gedit/plugins/snippets/js.xml && sudo rm -rf gedit-snippet-jquery
在我的终端中它可以正常工作。
但是通过GUI只是打开,我输入密码,按下回车,然后又关闭了。
我想要只执行第一个&&
之前的命令。
这是我的Python函数(带有命令):
def on_install_jquery_code_snippet_for_gedit_activate(self, widget):
""" Install Jquery code snippet for Gedit. """
cmd="gnome-terminal -x sudo git clone git://github.com/pererinha/gedit-snippet-jquery.git && sudo cp -f gedit-snippet-jquery/js.xml /usr/share/gedit/plugins/snippets/js.xml && sudo rm -rf gedit-snippet-jquery"
p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT,
close_fds=False)
self.status.set_text(p.stdout.read()) #show response in 'status
shell=True
传递列表参数(附加的列表项将传递给/bin/sh
,而不是命令)- 在大多数情况下,您不需要它。使用字符串代替(即,如果使用shell=True
,则删除shlex.split()
)。 - jfs