我正在运行以下python代码来测试pandoc的markdown变体生成epub / html文件的自动化。当我从网上运行它(即使用python和cgi)时,我得到一个失败和返回代码为83.当我从命令行运行它时,它完美地工作。它需要从网络上运行。
我发现pandoc和返回代码83的唯一参考与pandoc-citeproc有关:https://groups.google.com/forum/#!topic/pandoc-discuss/rV3eiZhwTlQ
下面的runcmd
函数从另一个程序中的Web运行,以生成pdf / LaTex,没有任何问题。
我已将错误输出添加到此帖的末尾。
非常感谢任何帮助。
#!/usr/bin/env python3
import cgi, cgitb, os, tempfile, zipfile, sys, shutil
import yaml, json, subprocess, re, datetime
# Enable module to test/debug CGI issues
cgitb.enable()
def runcmd(*args):
try:
result = subprocess.check_output(list(args), universal_newlines=True)
print("Ran command {} with {} {}".format(args[0], args[1:], result))
except subprocess.CalledProcessError as cpe:
print(str(cpe))
print(str(cpe.returncode))
print(str(cpe.output))
print("PATH: {}".format(str(sys.path)))
print("FAIL: {} with {}".format(args[0], args[1:]))
except OSError as ose:
print(str(ose))
except AttributeError as ae:
print(str(ae))
html_stuff = """Content-Type: text/html\n\n<!DOCTYPE html>\n<html lang="en">\n<head>\n<title>Generate FYP from Markdown files -- by MF</title>\n<meta charset="utf-8">\n</head>\n<body>\n<h1>Pandoc Test</h1>\n<p></p>\n<div name="messages" id="messages"></div>\n</body>\n</html>"""
print(html_stuff)
test1_args = ['/usr/bin/pandoc', '--smart', '--toc', '--standalone', '--csl=/tmp/tmp0u5dtk/acm-sig-proceedings.csl', '--bibliography=/tmp/tmp0u5dtk/biblio.bib', '--filter=/usr/bin/pandoc-citeproc', '/tmp/tmp0u5dtk/GeneratedEpubMetadata.yaml', '/tmp/tmp0u5dtk/GeneratedEpubPreamble.md', '/tmp/tmp0u5dtk/first_chapter.md', '/tmp/tmp0u5dtk/another_chapter.md', '/tmp/tmp0u5dtk/ModifiedEpubAppendix.md', '--output=/tmp/tmp0u5dtk/GeneratedDoc.html']
test2_args = ['/usr/bin/pandoc', '--smart', '--toc', '--standalone', '--csl=/tmp/tmp0u5dtk/acm-sig-proceedings.csl', '--bibliography=/tmp/tmp0u5dtk/biblio.bib', '--filter=/usr/bin/pandoc-citeproc', '/tmp/tmp0u5dtk/GeneratedEpubMetadata.yaml', '/tmp/tmp0u5dtk/GeneratedEpubPreamble.md', '/tmp/tmp0u5dtk/first_chapter.md', '/tmp/tmp0u5dtk/another_chapter.md', '/tmp/tmp0u5dtk/ModifiedEpubAppendix.md', '--output=/tmp/tmp0u5dtk/GeneratedDoc.epub']
print("<p>****************\nrunning with test1_args\n****************</p>")
runcmd(*test1_args)
print("<p>****************\nrunning with test2_args\n****************</p>")
runcmd(*test2_args)
错误输出:
**************** 使用test1_args运行 ****************
命令&#39; [&#39; / usr / bin / pandoc&#39;,&#39; - smart&#39;,&#39; - toc&#39;,&#39; - -standalone&#39;,&#39; - csl = / tmp / tmp0u5dtk / acm-sig-proceedings.csl&#39;,&#39; - bibliography = / tmp / tmp0u5dtk / biblio.bib&#39;, &#39; - filter = / usr / bin / pandoc-citeproc&#39;,&#39; /tmp/tmp0u5dtk/GeneratedEpubMetadata.yaml' ;,&#39; /tmp/tmp0u5dtk/GeneratedEpubPreamble.md' ;,&#39; /tmp/tmp0u5dtk/first_chapter.md' ;,&#39; /tmp/tmp0u5dtk/another_chapter.md' ;,&#39; /tmp/tmp0u5dtk/ModifiedEpubAppendix.md', &#39; - 输出= / TMP / tmp0u5dtk / GeneratedDoc.html&#39;]&#39;返回非零退出状态83
83
路径:[&#39; / var / www / cgi-bin&#39;,&#39; /usr/lib/python3.2' ;,&#39; /usr/lib/python3.2 / plat-linux2&#39;,&#39; /usr/lib/python3.2/lib-dynload' ;,&#39; /usr/local/lib/python3.2/dist-packages', &#39; / usr / lib中/ python3 / DIST-包&#39;]
失败:/ usr / bin / pandoc with(&#39; - smart&#39;,&#39; - toc&#39;,&#39; - standalone&#39;,&#39; --csl = / tmp / tmp0u5dtk / acm-sig-proceedings.csl&#39;,&#39; - bibliography = / tmp / tmp0u5dtk / biblio.bib&#39;,&#39; - filter = / usr / bin / pandoc-citeproc&#39;,&#39; /tmp/tmp0u5dtk/GeneratedEpubMetadata.yaml' ;,&#39; /tmp/tmp0u5dtk/GeneratedEpubPreamble.md' ;,&#39; / tmp / tmp0u5dtk /first_chapter.md' ;,&#39; /tmp/tmp0u5dtk/another_chapter.md' ;,&#39; /tmp/tmp0u5dtk/ModifiedEpubAppendix.md' ;,&#39; - output = / tmp /tmp0u5dtk/GeneratedDoc.html')
**************** 使用test2_args运行 ****************
命令&#39; [&#39; / usr / bin / pandoc&#39;,&#39; - smart&#39;,&#39; - toc&#39;,&#39; - -standalone&#39;,&#39; - csl = / tmp / tmp0u5dtk / acm-sig-proceedings.csl&#39;,&#39; - bibliography = / tmp / tmp0u5dtk / biblio.bib&#39;, &#39; - filter = / usr / bin / pandoc-citeproc&#39;,&#39; /tmp/tmp0u5dtk/GeneratedEpubMetadata.yaml' ;,&#39; /tmp/tmp0u5dtk/GeneratedEpubPreamble.md' ;,&#39; /tmp/tmp0u5dtk/first_chapter.md' ;,&#39; /tmp/tmp0u5dtk/another_chapter.md' ;,&#39; /tmp/tmp0u5dtk/ModifiedEpubAppendix.md', &#39; - 输出= / TMP / tmp0u5dtk / GeneratedDoc.epub&#39;]&#39;返回非零退出状态83
83
路径:[&#39; / var / www / cgi-bin&#39;,&#39; /usr/lib/python3.2' ;,&#39; /usr/lib/python3.2 / plat-linux2&#39;,&#39; /usr/lib/python3.2/lib-dynload' ;,&#39; /usr/local/lib/python3.2/dist-packages', &#39; / usr / lib中/ python3 / DIST-包&#39;]
失败:/ usr / bin / pandoc with(&#39; - smart&#39;,&#39; - toc&#39;,&#39; - standalone&#39;,&#39; --csl = / tmp / tmp0u5dtk / acm-sig-proceedings.csl&#39;,&#39; - bibliography = / tmp / tmp0u5dtk / biblio.bib&#39;,&#39; - filter = / usr / bin / pandoc-citeproc&#39;,&#39; /tmp/tmp0u5dtk/GeneratedEpubMetadata.yaml' ;,&#39; /tmp/tmp0u5dtk/GeneratedEpubPreamble.md' ;,&#39; / tmp / tmp0u5dtk /first_chapter.md' ;,&#39; /tmp/tmp0u5dtk/another_chapter.md' ;,&#39; /tmp/tmp0u5dtk/ModifiedEpubAppendix.md' ;,&#39; - output = / tmp /tmp0u5dtk/GeneratedDoc.epub')