下面是我的代码:
#!/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会报告缺少配置文件。在命令行上调用时,一切都很正常,配置文件也在那里。有人能理解这一点吗?我迷路了。
发布于 2013-06-25 19:30:04
试试这个:
asciidoc_call = ["asciidoc","-b", "docbook45", asciidoc_file_name]另一个调用将调用带有"-b docbook45"的ascidoc作为一个单独的选项,这将不起作用。
发布于 2015-09-14 21:54:06
这个问题很古老..。无论如何,asciidoc是用Python语言实现的,它还包括可以作为Python程序的模块使用的asciidocapi.py。模块文档字符串表示:
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()。
https://stackoverflow.com/questions/17295548
复制相似问题