通过python子进程调用ascidoc时失败

2024-09-30 22:28:05 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我的代码:

   #!/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)

输出如下:

^{pr2}$

当通过python子进程调用时,asciidoc会抱怨缺少配置文件。当在命令行调用时,一切正常,配置文件就在那里。有人能理解吗?我迷路了。在


Tags: 代码nameimporttxtbinusr配置文件call
2条回答

试试这个:

asciidoc_call = ["asciidoc","-b", "docbook45", asciidoc_file_name]

另一个调用将使用"-b docbook45"作为一个单独的选项调用ascidoc,这不起作用。在

这个问题很古老。。。无论如何,asciidoc是在Python中实现的,它还包括可以用作Python程序模块的asciidocapi.py。模块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()。在

相关问题 更多 >