pythons subprocess.call 无法识别参数“--outdir”,但可以在终端中使用

Parameter "--outdir" is not recognised via pythons subprocess.call but does work in terminal

我想编写一个 python 脚本来自动将 libreoffice ott 模板转换为普通的 odt 文件。 如果我去终端 (bash shell) 并输入:

soffice --headless --convert-to odt "/path/template.ott" --outdir '/targetpath/template.odt'

输出符合预期,一个位于新目标位置的 odt 文件。

当我编写脚本时(像这样:

oldfile
outdir = pipes.quote(/targetpath/template.odt)
subprocess.call(['soffice --headless --convert-to odt /path/template.ott --outdir /pathtarget/template.odt'])

输出给了我

[Errno 2] No such file or directory

当我尝试这样拨打电话时:

subprocess.call(["soffice", "--headless", "--convert-to", "odt", pipes.quote(oldpath),outdir])

结果为soffice的帮助文本,原因:

    LibreOffice 4.2.8.2 420m0(Build:2)

    Unknown option: --outdir /targetpath/template.odt
...

为什么不试试 os.system?

os.system('soffice --headless --convert-to odt "/path/template.ott" --outdir "/targetpath/template.odt"')