subprocess.Popen 不会 运行 我的 python 程序
subprocess.Popen will not run my python program
所以我尝试为我正在制作的文字游戏制作一个启动器,我需要启动器根据我选择的扩展 运行 作为游戏的一部分。然而,在创建启动器并对其进行测试之后,我意识到一切正常,直到启动器应该执行另一个 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()
应该是:
subprocess.Popen("python " + filepath, shell=True)
如果还是不行,能不能把代码的输出贴出来?
所以我尝试为我正在制作的文字游戏制作一个启动器,我需要启动器根据我选择的扩展 运行 作为游戏的一部分。然而,在创建启动器并对其进行测试之后,我意识到一切正常,直到启动器应该执行另一个 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()
应该是:
subprocess.Popen("python " + filepath, shell=True)
如果还是不行,能不能把代码的输出贴出来?