我使用以下命令启动openoffice:
soffice --accept="socket,host=localhost,port=8100;urp;StarOffice.Service" --headless --nofirststartwizard
以下命令将确保openoffice在端口8100上接受连接:
netstat -nap | grep office
输出:
tcp 0 0 127.0.0.1:8100 0.0.0.0:* LISTEN 2467/soffice.bin
使用Python脚本启动openoffice流程:
command = [
'soffice',
'--accept=socket,host=localhost,port=8100;urp;StarOffice.Service',
'--headless',
'--nofirststartwizard'
]
subprocess.Popen(command, shell=True)
由于某种原因,当我尝试使用此python脚本启动openoffice时,netstat命令不会输出任何内容。该过程已存在,但不接受连接。我究竟做错了什么 ?
从文档中:
在shell = True的Unix上,shell默认为/ bin / sh。如果args是字符串,则该字符串指定要通过外壳执行的命令。
如果args是序列,则第一项指定命令字符串,任何其他项都将被视为shell本身的其他参数。
在这里,您应该删除shell=True
以将参数传递给soffice
而不是将参数传递给shell:
subprocess.Popen(command)
要使用shell=True
,您需要将所有参数构建到一个命令中(当然需要对参数进行转义):
subprocess.Popen(command.join(' '), shell=True)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句