子流程.Popen不会运行我的python程序

2024-04-28 19:39:23 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我试着为我正在制作的文本游戏制作一个启动程序,我需要启动程序来运行游戏的一部分,基于我选择的扩展。然而,在创建并测试了启动器之后,我意识到在启动器执行另一个python程序之前,一切都很正常。不是执行程序,而是结束,我不知道为什么。这是我的代码:

import easygui as e
import os
import subprocess
def Launch():
    expansions = []
    file = open("dlc.txt")
    reading = True
    while reading == True:
        temp = file.readline().strip()
        if temp == "":
            reading = False
        elif temp == "The Forgotten Lands":
            expansions.append("The Forgotten Lands (Main Game)")
        else:
            expansions.append(temp)
    game = e.choicebox("Welcome to The Forgotten Lands launcher. Please pick an expansion.","Launcher",choices=expansions)
    if game is None:
        os._exit(0)
    else:
        if game == "The Forgotten Lands (Main Game)":
            game = "The Forgotten Lands"
        dir_path = os.path.dirname(os.path.realpath(__file__))
        filepath = (dir_path + "/" + game + "/" + game + ".py")
        filepath = filepath.replace("/", "\/")
        filepath = filepath.replace("/", "")
        subprocess.Popen(filepath, shell=True)

Launch()

Tags: thepathimport程序gametrueifos
1条回答
网友
1楼 · 发布于 2024-04-28 19:39:23

它应该是:

subprocess.Popen("python " + filepath, shell=True)

如果这不起作用,你能把代码的输出放进去吗?在

相关问题 更多 >