user1538560 user1538560 - 1 month ago 12
Python Question

start openoffice process with python to use with pyuno using subprocess

I use this command to start openoffice:

soffice --accept="socket,host=localhost,port=8100;urp;StarOffice.Service" --headless --nofirststartwizard


The following command will ensure that openoffice is accepting connections on port 8100:

netstat -nap | grep office


output:

tcp 0 0 127.0.0.1:8100 0.0.0.0:* LISTEN 2467/soffice.bin


Python script to start openoffice process:

command = [
'soffice',
'--accept=socket,host=localhost,port=8100;urp;StarOffice.Service',
'--headless',
'--nofirststartwizard'
]
subprocess.Popen(command, shell=True)


For some reason, the netstat command outputs nothing when i try to start openoffice with this python script. the process is there, but it does not accept connections.
What am i doing wrong ?

Answer

From the documentation:

On Unix with shell=True, the shell defaults to /bin/sh. If args is a string, the string specifies the command to execute through the shell.

If args is a sequence, the first item specifies the command string, and any additional items will be treated as additional arguments to the shell itself.

Here, you should just remove shell=True to pass the arguments to soffice instead of passing the arguments to the shell:

subprocess.Popen(command)

To use shell=True, you need to build all arguments into a single command (arguments would need to be escaped of course):

subprocess.Popen(command.join(' '), shell=True)