gpt4 book ai didi

python - 从 python 启动 gnu screen ?

转载 作者:太空宇宙 更新时间:2023-11-03 13:50:08 24 4
gpt4 key购买 nike

我尝试从子进程调用中使用 gnu screen 执行服务器守护进程,但它甚至没有启动

subprocess.call(["screen", "-dmS test ./server"])

有人告诉我运行 screen 需要终端,因此我不能简单地通过调用来执行它。你能告诉我一些代码来做到这一点吗?

最佳答案

尝试

subprocess.call( ["screen", "-d", "-m", "-S", "test", "./server"] )

您需要将参数字符串分成单独的参数,每个字符串一个。

这是subprocess 文档中的相关引用:

On UNIX, with shell=False (default): In this case, the Popen class uses os.execvp() to execute the child program. args should normally be a sequence. A string will be treated as a sequence with the string as the only item (the program to execute).

On UNIX, with shell=True: If args is a string, it specifies the command string 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 shell arguments.

因此,默认情况下,参数将完全按照您提供的方式使用;它不会尝试将字符串解析为多个参数。如果您将 shell 设置为 true,您可以尝试以下操作:

subprocess.call("screen -dmS test ./server", shell=True)

并且字符串会像命令行一样被解析。

关于python - 从 python 启动 gnu screen ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10817929/

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