简体   繁体   中英

Failed to Open Display error while running python subprocess and Libreoffice 6.2 in CentOS6

I need to run Libreoffice --covert-to to convert an excel file to html page. The current code works well within the windows machine. But in AWS, CentOS6, it's producing an error as "Failed to open display" . Here is my code

import subprocess
cwdir = '/opt/libreoffice6.2/program'
excel_path = '/home/ec2-user/PythonCode/testing/Book1.xlsx'
dest_path = '/home/ec2-user/PythonCode/testing'
html_command = ["soffice", "--headless", "--convert-to", "html", "--outdir", 
               dest_path, excel_path]
subprocess.run(html_command, shell=True, cwd=cwdir)`

I was able to convert excel file to html file with some minor changes. The values inside list is not working so I have to provide the soffice convert-to query as a string value and the folder contains the input excel file and destination folder , where the html file to be stored,must be different.

import subprocess
cwdir = '/opt/libreoffice6.2/program'
excel_path = '/home/ec2-user/PythonCode/testing/Book1.xlsx'
dest_path = '/home/ec2-user/PythonCode/testing/output'
html_command = r"soffice --headless --convert-to html --outdir " + " " + dest_path + " " + excel_path
subprocess.run(html_command, shell=True, cwd=cwdir)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM