import schedule import time import subprocess def run_in_new_window(): script_path = r"D:\drug\pdd1\pdd_new.py" # 关键修改:在命令末尾添加 || exit,失败时自动关闭窗口 cmd = f'start cmd /k "python {script_path} || exit"' subprocess.Popen(cmd, shell=True) print(f"[{time.ctime()}] 已启动新窗口执行任务(失败将自动关闭)") # 每10分钟执行一次 schedule.every(1).minutes.do(run_in_new_window) print("调度器已启动,每10分钟会弹出一个新cmd窗口运行pdd_new.py") while True: schedule.run_pending() time.sleep(1)