简体   繁体   中英

subprocess.Popen will not run my python program

So I tried making a launcher for a text games that I am making and I need the launcher to run a part of the game based on what expansions I picked. However, after creating the launcher and testing it, I realised that everything works fine up until the part where the launcher is supposed to execute another python program. Instead of executing the program, it just ends and I am not sure why. Here is my code:

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()

It should be:

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

If that doesn't work, would you be able to put the output of the code please?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM