Error calling LibreOffice from Python

前端 未结 1 1956
名媛妹妹
名媛妹妹 2021-01-14 08:15

Calling LibreOffice to convert a document to text...

This works fine from the linux command line:

soffice --headless --convert-to txt:\"Text\" docume         


        
相关标签:
1条回答
  • 2021-01-14 08:26

    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.

    0 讨论(0)
提交回复
热议问题