调用 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/