【发布时间】:2015-07-01 03:04:15
【问题描述】:
尝试使用subprocess 进行递归grep。代码如下:
import subprocess
from subprocess import CalledProcessError, check_output
try:
out = check_output(
["grep",
"-R",
'--include="*.org"',
"abc",
"/home/fenton/projects/docs-DIR/documentation/"],
stderr=subprocess.STDOUT)
print(out)
except CalledProcessError as e:
print("command failed")
当我运行它时,它失败了。
python % python find_docs_2.py
command failed
从命令行执行此操作成功:
python % grep -R --include="*.org" abc /home/fenton/projects/docs-DIR/documentation/
/home/fenton/projects/docs-DIR/documentation/zsh.org: % ./test.sh -f abc
/home/fenton/projects/docs-DIR/documentation/zsh.org: abc
...
【问题讨论】: