这是我的代码:
#!/usr/bin/python
import subprocess
asciidoc_file_name = '/tmp/redoc_2013-06-25_12:52:19.txt'
asciidoc_call = ["asciidoc","-b docbook45",asciidoc_file_name]
print asciidoc_call
subprocess.call(asciidoc_call)
这是输出:
labamba@lambada:~$ ./debug.py
['asciidoc', '-b docbook45', '/tmp/redoc_2013-06-25_12:52:19.txt']
asciidoc: FAILED: missing backend conf file: docbook45.conf
labamba@lambada:~$ asciidoc -b docbook45 /tmp/redoc_2013-06-25_12\:52\:19.txt
labamba@lambada:~$ file /tmp/redoc_2013-06-25_12\:52\:19.xml
/tmp/redoc_2013-06-25_12:52:19.xml: XML document text
labamba@lambada:~$ file /etc/asciidoc/docbook45.conf
/etc/asciidoc/docbook45.conf: HTML document, ASCII text, with very long lines
当通过python子进程调用时,asciidoc
会抱怨缺少配置文件。在命令行上调用时,一切都很好,配置文件就在那里。任何人都可以理解这个吗?我输了。
答案 0 :(得分:2)
试试这个:
asciidoc_call = ["asciidoc","-b", "docbook45", asciidoc_file_name]
另一个调用将调用带有"-b docbook45"
的ascidoc作为单个选项,这将无效。
答案 1 :(得分:2)
问题是陈旧的......无论如何,asciidoc
是用Python实现的,它还包含asciidocapi.py
,它可以用作Python程序中的模块。模块docstring说:
asciidocapi - AsciiDoc API wrapper class.
The AsciiDocAPI class provides an API for executing asciidoc. Minimal example
compiles `mydoc.txt` to `mydoc.html`:
import asciidocapi
asciidoc = asciidocapi.AsciiDocAPI()
asciidoc.execute('mydoc.txt')
- Full documentation in asciidocapi.txt.
- See the doctests below for more examples.
为了简化,它实现了AsciiDocAPI
类 - 在初始化时 - 搜索asciidoc
脚本并将其作为模块导入场景后面。这样,您可以在Python中更自然地使用它,并且可以避免使用subprocess.call()
。