不能同时打开多个程序

2024-09-30 22:19:34 发布

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

我正在使用Python3编写一段代码,该代码充当各种“白昼骗局”的接口。我使用一个非常基本的设置,只需输入()和os.system()来查找和打开特定的文件。它工作正常,但有一个小问题

界面使用cmd提示符,我已经设置好了,输入数字1-4将打开用于修改游戏的程序和可执行文件。但是,有些程序需要在其他程序运行时保持打开状态。例如,BVHR会话抓取器必须与SaveInjector接口一起运行,因为SaveInjector需要从抓取器接收特定代码

这里有一个问题,代码的设置方式是一次只能运行一个文件。我不确定到底是什么原因造成的,但我会尽力解释发生了什么。例如,在cmd提示符窗口中输入数字1时,会打开BHVR会话抓取器(如预期)。在那之后,接口变得不可用,直到我关闭BHVR会话抓取器。它处于活动状态时,我无法在其中键入任何内容,因此我无法同时打开多个程序

不完全确定这是否是有意的,但我希望这是可以避免的。如果有人对这个问题有任何了解,请在评论中告诉我如何解决这个问题

import os.path
def interface():
    os.system('cls' if os.name == 'nt' else 'clear')
    print("""
    \n\nSelect a cheat below:
    \n
    \n1: BHVR Session Grabber
    \n2: SaveInjector Interface
    \n3: Rank / Shards Editor
    \n4: Exit\n
    """)

def checker():
    interface()
    lst = ['1','2','3','4']
    good_input = input(">")

    global user_input
    user_input = None
    while not user_input:
        if good_input in lst: 
            user_input = good_input
        else:
            print("Enter a valid integer.")
            good_input = input(">")
        
checker()
cwd = os.getcwd()

def selection():
    if user_input == '1':
        f = (os.path.join(cwd, 'Programs', 'BHVRSession', 'CookieFinder.exe'));
        os.system(f)
        checker()
        selection()
        
    elif user_input == '2':
        os.system('cmd /k "cd Programs & cd Injector & SI.exe & cd.. & cd.. & Ultimate.py"')
        
    elif user_input == '3':
        f = (os.path.join(cwd, 'Programs', 'RankShards', 'Sender.exe'));
        os.system(f)
        checker()
        selection()
        
    elif user_input == '4':
        os.system('cmd /k "taskkill/im py.exe"')

selection()

Tags: path代码程序cmdinputoscheckercd
1条回答
网友
1楼 · 发布于 2024-09-30 22:19:34

这里的问题是os.system()正在阻塞。这意味着它只会在运行的程序完成后返回并继续执行Python代码。相反,您应该查看subprocess包,以了解如何派生一个可以与Python程序并行运行的新进程

相关问题 更多 >