2017-07-16 88 views
0

所以我嘗試製作一個我正在製作的文本遊戲的啓動器,並且我需要啓動器根據我選擇的擴展來運行遊戲的一部分。然而,在創建啓動器並測試它之後,我意識到一切工作正常,直到啓動器應該執行另一個python程序的部分。而不是執行程序,它只是結束,我不知道爲什麼。這裏是我的代碼:subprocess.Popen不會運行我的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() 

回答

0

它應該是:

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

如果不工作,你就可以把輸出的代碼嗎?

+0

這工作,謝謝! – PHDBanana