读取源时,Sphinx会发现错误

时间:2017-02-07 07:14:19

标签: bash python-sphinx restructuredtext

我正在使用sphinx进行文档编制。并使用make html并通过bash脚本制作latexpdf。 在运行bash脚本时,当运行make html时,它会在读取源之后的第一个文件中显示ERROR。

make clean
+ make clean
rm -rf _build/*
make html
+ make html
sphinx-build -b html -d _build/doctrees   . _build/html
Running Sphinx v1.3b3
making output directory...
loading pickled environment... not yet created
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 2 source files that are out of date
updating environment: 2 added, 0 changed, 0 removed
reading sources... [100%] index
/home/sphinx/Inder.rst:12:WARNING: Bullet list ends without a blank line; unexpected unindent.
/home/sphinx/Inder.rst:12: ERROR: Document may not end with a transition.
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
writing output... [100%] index                   

如何在bash脚本中捕获此错误或将其发送到另一个变量。 我用make html尝试了grep ERROR,但它给出了空白。

1 个答案:

答案 0 :(得分:0)

sphinx-build可能会在stdout和stderr上打印输出,因此您可能希望捕获两个流。

您可以这样做:

out=$(make html 2>&1)
if grep -q 'ERROR: ' <<< "$out"; then
    # do some error handling
fi