gpt4 book ai didi

python - 使用 python 启动 openoffice 进程,以便使用子进程与 pyuno 一起使用

转载 作者:行者123 更新时间:2023-12-01 05:28:46 26 4
gpt4 key购买 nike

我使用此命令启动 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 

启动 openoffice 进程的 Python 脚本:

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

出于某种原因,当我尝试使用此 python 脚本启动 openoffice 时,netstat 命令不输出任何内容。该进程存在,但它不接受连接。我做错了什么?

最佳答案

来自 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.

在这里,您应该删除 shell=True 以将参数传递给 soffice,而不是将参数传递给 shell:

subprocess.Popen(command)

要使用shell=True,您需要将所有参数构建到单个命令中(当然参数需要转义):

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

关于python - 使用 python 启动 openoffice 进程,以便使用子进程与 pyuno 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20787712/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com