Sphinx 在阅读源代码时捕获错误

Sphinx catch error while reading sources

我正在使用 sphinx 进行文档处理。并通过 bash 脚本使用 make html 和 make latexpdf。 当 运行 运行 bash 脚本时,当 make html 是 运行 时,它在读取源文件后的第一个文件中显示错误。

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,但它给出了空白。

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

您可以这样做:

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