相关疑难解决方法(0)

subprocess.call使用字符串vs使用列表

我试图使用rsync与subprocess.call.奇怪的是,如果我传递subprocess.call一个字符串,它可以工作,但它不适用于列表(ala,Python的doc).

使用字符串调用sp.call:

In [23]: sp.call("rsync -av content/ writings_raw/", shell=True)
sending incremental file list

sent 6236 bytes  received 22 bytes  12516.00 bytes/sec
total size is 324710  speedup is 51.89
Out[23]: 0
Run Code Online (Sandbox Code Playgroud)

使用列表调用sp.call:

In [24]: sp.call(["rsync", "-av", "content/", "writings_raw/"], shell=True)
rsync  version 3.0.9  protocol version 30
Copyright (C) 1996-2011 by Andrew Tridgell, Wayne Davison, and others.
Web site: http://rsync.samba.org/
Capabilities:
    64-bit files, 64-bit inums, 32-bit timestamps, 64-bit long ints,
    socketpairs, hardlinks, symlinks, IPv6, batchfiles, inplace,
    append, ACLs, xattrs, iconv, symtimes

rsync comes …
Run Code Online (Sandbox Code Playgroud)

python subprocess

27
推荐指数
1
解决办法
2万
查看次数

如何用Python Popen做多个参数?

我正在尝试制作一个有按钮的PyGtk Gui.当用户按下此按钮时,gnome-terminal提示用户输入密码.

然后它将为JQuery片段克隆这个Git存储库gedit.

然后,它将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
Run Code Online (Sandbox Code Playgroud)

它在我的终端工作正常.

但是,通过它刚打开的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
Run Code Online (Sandbox Code Playgroud)

python subprocess pygtk popen gnome-terminal

17
推荐指数
1
解决办法
5万
查看次数

标签 统计

python ×2

subprocess ×2

gnome-terminal ×1

popen ×1

pygtk ×1