【问题标题】:pygtk OSError: [Errno 2] No such file or directory. subprocess.Popen PIPE commandpygtk OSError: [Errno 2] 没有这样的文件或目录。 subprocess.Popen PIPE 命令
【发布时间】:2011-09-23 16:20:45
【问题描述】:

我是 python 新手,我正在尝试使用两个查找命令创建一个仅搜索 2 个目录的搜索栏,并将结果输出到有序列表 []。

def search_entry(self, widget,):
            s1 = subprocess.Popen(['find /home/bludiescript/tv-shows', '-type f'], shell=False, stdout=subprocess.PIPE)
            s2 = subprocess.Popen(['find /media/FreeAgent\ GoFlex\ Drive/tobins-media', '-type f'],  stdin=s1.stdout, shell=False, stdout=subprocess.PIPE)
            s1.stdout.close()
            self.contents = "\n".join(self.list)
            s2.communicate(self.contents)

我的搜索栏:

self.search = gtk.Entry()
            self.search.connect("activate", self.search_entry,)
            self.box1.pack_start(self.search, True, True, 0)
            self.search.show()

错误消息:

File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1228, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory

【问题讨论】:

    标签: python pygtk subprocess pipe


    【解决方案1】:

    分离 args 列表中的所有参数:

    s1 = subprocess.Popen(['find','/home/bludiescript/tv-shows', '-type','f'], shell=False, stdout=subprocess.PIPE)
    s2 = subprocess.Popen(['find','/media/FreeAgent\ GoFlex\ Drive/tobins-media', '-type', 'f'],  stdin=s1.stdout, shell=False, stdout=subprocess.PIPE)
    

    MINE 上的输出

    >>> import subprocess
    >>> s1 = subprocess.Popen(['find /home/bludiescript/tv-shows', '-type f'], shell=False, stdout=subprocess.PIPE)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/lib/python2.7/subprocess.py", line 672, in __init__
        errread, errwrite)
      File "/usr/lib/python2.7/subprocess.py", line 1201, in _execute_child
        raise child_exception
    OSError: [Errno 2] No such file or directory
    >>> s1 = subprocess.Popen(['find','/home/bludiescript/tv-shows', '-type','f'], shell=False, stdout=subprocess.PIPE)
    >>> find: `/home/bludiescript/tv-shows': No such file or directory
    

    第一个是您的原始代码,它引发了 python 异常。第二个运行正确,但“find”抱怨,因为我的系统上没有“bludiescript/tv-shows”目录。

    【讨论】:

    • 谢谢,是的,它停止给我错误,我没有注意到 find 是目录的一部分。
    【解决方案2】:

    您的意思是在第 2 行找到吗?似乎在查找文件“正常”时出错

    【讨论】:

    • 是的,谢谢你,我改变了它,但它不是导致错误的原因,它是一个错字。
    猜你喜欢
    • 2018-12-06
    • 1970-01-01
    • 2015-09-30
    • 1970-01-01
    • 1970-01-01
    • 2018-11-20
    • 2017-06-13
    • 2012-07-18
    • 1970-01-01
    相关资源
    最近更新 更多