我是python的新手,我正在尝试使用两个find命令创建一个只搜索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
答案 0 :(得分:2)
分隔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异常。第二个运行正确,但&#34;发现&#34;抱怨因为我没有&#34; bludiescript / tv-shows&#34;我系统上的目录。
答案 1 :(得分:0)
你的意思是在第2行找到?它看起来像找错文件&#34;罚款&#34;