Error calling LibreOffice from Python

非 Y 不嫁゛ 提交于 2019-12-20 02:28:15

问题


Calling LibreOffice to convert a document to text...

This works fine from the linux command line:

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

But I get an error when I try to run the same command from Python:

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

Error: Please reverify input parameters...

How do I get the command to run from Python?


回答1:


This is the code you should use:

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

This is the same line you posted, without the quotes around txt:Text.

Why are you seeing the error? Simply put: because soffice does not accept txt:"Text". It only accepts txt:Text.

Why is it working on the shell? Your shell implicitly removes quotes around arguments, so that the command that gets executed is actually:

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

Try running this command:

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

Quotes won't be removed and you'll see the Please verify input parameters message you are getting with Python.



来源:https://stackoverflow.com/questions/30125574/error-calling-libreoffice-from-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!