我是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()
errormsg:
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
分隔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)
>>> 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"目录。
你是说在第2行找到吗?它看起来是错误的查找文件"fine"