python - 从 Python 调用 LibreOffice 时出错

标签 python subprocess converters libreoffice

调用 LibreOffice 将文档转换为文本...

这在 linux 命令行下运行良好:

soffice --headless --convert-to txt:"Text" document_to_convert.doc

但是当我尝试从 Python 运行相同的命令时出现错误:

subprocess.call(['soffice', '--headless', '--convert-to', 'txt:"Text"', 'document_to_convert.doc'])

Error: Please reverify input parameters...

如何让命令从 Python 运行?

最佳答案

这是您应该使用的代码:

subprocess.call(['soffice', '--headless', '--convert-to', 'txt:Text', 'document_to_convert.doc'])

这是您发布的同一行,txt:Text 没有引号。

为什么会看到错误? 简单地说:因为 soffice 不接受 txt:"Text"。它只接受 txt:Text

为什么它在 shell 上工作?您的 shell 隐式删除了参数周围的引号,因此执行的命令实际上是:

soffice --headless --convert-to txt:Text document_to_convert.doc

尝试运行这个命令:

soffice --headless --convert-to txt:\"Text\" document_to_convert.doc

引号不会被删除,您会看到 请验证输入参数 消息,您正在使用 Python。

关于python - 从 Python 调用 LibreOffice 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30125574/

相关文章:

python - 线性回归 - 均方误差太大

Python:非阻塞+非失效进程

python - 将 daemontools 与生成子进程的 Python 脚本一起使用

wpf - 您可以将不透明度应用于系统定义的画笔吗?

c# - 将表从 SQL Server 2008 复制到 MS Access 2007

python - 将 Tecplot ascii 转换为 Python numpy

python - 一维 CNN (Keras) 的输入形状

python - 读取主机名列表并解析为 IP 地址

python - 将任意数量的不同列表或元组转换为一个列表的更 Pythonic 方式

php - 从 python 调用 php 函数