2016-12-28 31 views
0

當我用「-V args」調用pandoc時,例如:'-V title =「Wartość」' 在Python腳本中,我得到的輸出沒有標題.. :(在python中調用pandoc的問題。提供「-V args」不起作用

實施例: 手動鍵入命令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

但是當我運行相同的共mmand在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

如何解決呢?

回答

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()列表。

+0

感謝您的幫助和糾正我的錯誤:) – ffg