이 코드를 실행하면 grep : write 오류가 발생합니다. 내가 무엇이 누락 되었습니까?grep : 쓰기 오류 : 서브 프로세스가있는 파이프가 깨졌습니다.
이 그것의 일부이다 :
while d <= datetime.datetime(year, month, daysInMonth[month]):
day = d.strftime("%Y%m%d")
print day
results = [day]
first=subprocess.Popen("grep -Eliw 'Algeria|Bahrain' "+ monthDir +"/"+day+"*.txt | grep -Eliw 'Protest|protesters' "+ monthDir +"/"+day+"*.txt", shell=True, stdout=subprocess.PIPE,)
output1=first.communicate()[0]
d += delta
day = d.strftime("%Y%m%d")
second=subprocess.Popen("grep -Eliw 'Algeria|Bahrain' "+ monthDir +"/"+day+"*.txt | grep -Eliw 'Protest|protesters' "+ monthDir +"/"+day+"*.txt", shell=True, stdout=subprocess.PIPE,)
output2=second.communicate()[0]
articleList = (output1.split('\n'))
articleList2 = (output2.split('\n'))
results.append(len(articleList)+len(articleList2))
w.writerow(tuple(results))
d += delta
난 당신이 뭘 하려는지 알아낼 수 없습니다. grep에 filename 인수를 주면 stdin에서 읽지 않습니다. 그래서 grep 프로세스의 출력을 두 번째 파이프로 파이프하는 이유는 무엇입니까? – Barmar
나는 알제리 또는 바레인이라는 키워드와 항의 또는 항의를 포함하는 파일을 필터링하고 있습니다. 실제로이 질문을 위해 단순화 한 lil이 더 복잡합니다. list1에있는 키워드 중 하나와 list2에있는 키워드 중 하나를 포함하는 모든 파일을 가져 오려고합니다. –
Python의 정규 표현식 라이브러리 인 're'을 사용하지 않은 특별한 이유는 무엇입니까? grep을 부르는 것을 막을 것입니다. –