I'm need to launch headless LibreOffice on a web server which processes Calc spreadsheet from template. I tried to do this straight in Python with the command below.
# Doesn't work as expected, no socket connection, "--accept ..." is ignored.
subprocess.Popen(['libreoffice', '--calc','--headless',
'--accept="socket,host=localhost,port=2002;urp;"','&'], shell=True)
However, when I launch Shell script from Python, everything is OK.
subprocess.call('/var/www/scripts/service_report_ods_prepare.sh', shell=True)
Shell script:
#!/bin/bash
app="soffice"
app_pid=`ps -ef | grep "$app" | awk '{print $2}'`
if `ps -p $app_pid > /dev/null`; then
echo "An instance of LibreOffice is running, pid = "$app_pid
echo "Not starting another instance."
else
libreoffice --headless --accept="socket,host=localhost,port=2002;urp;"& > /dev/null 2>&1
fi
What is wrong with my Python code? Thanks in advance.