在python中调用pandoc的问题。提供“-V args”不起作用

时间:2016-12-28 13:17:30

标签: python pandoc pypandoc

当我用“-V args”调用pandoc时,例如:'-V title =“Wartość”' 在Python脚本中,我得到没有标题的输出.. :(

实施例: 手动输入pandoca命令(在终端中):

/usr/bin/pandoc  /home/user/program/content.md -V title="Wartość" 
-V authors="Jerry" --output=/home/user/program/outputs/book_22.pdf

它有效:) 输出文件: pandoc output when use manually pandoc in the terminal

但是当我在python中运行相同的命令(调用pandoc)时:

 subprocess.call(['/usr/bin/pandoc', '/home/user/program/content.md', '-V title="Wartość", -V authors="Jerry" ', '--output=/home/user/program/outputs/book_33.pdf'])

输出文件: pandoc output when I call to him from python script

如何解决?

1 个答案:

答案 0 :(得分:0)

您假设您正在运行"相同的命令"在Python中是不正确的。当它们应该分开时,你将参数组合成一个字符串。

subprocess.call(['/usr/bin/pandoc', '/home/user/program/content.md',
    '-V',  'title="Wartość"', '-V', 'authors="Jerry"', 
    '--output=/home/user/program/outputs/book_33.pdf'])

将命令行转换为适合subprocess.call()的列表的简便方法是shlex.split()