【发布时间】:2016-10-22 21:40:28
【问题描述】:
我想编写一个 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
...
【问题讨论】:
-
您是否尝试将 shell=True 添加到子进程调用中?
-
确实,为了将命令作为一个字符串传递,添加 shell=True 是一种解决方案!多谢。这确实是一个已经回答的问题 (stackoverflow.com/questions/18962785/…)。但是,我仍然无法让它与列表一起使用,同样,stackoverflow.com/questions/15109665/… 中确实提到了该错误。
标签: python bash subprocess libreoffice soffice