from winpty import PtyProcess class BuildAndRelease: def __init__(self): self.commands = [ "python clean_build_all.py", "python build_all.py", "python make_release.py", "python clean_build_all.py" ] self.user_input = input("请输入conda python环境的名称(例如:base): ") def __run_command(self, command): try: # 如果是"python build_all.py"命令,先获取用户输入 if "python build_all.py" == command: command += " " command += f"-python_env_name={self.user_input}" # 使用PtyProcess来运行命令 proc = PtyProcess.spawn(["powershell", "-Command", command]) proc.setwinsize(20, 9999) # 读取输出并打印到当前终端 while True: data = proc.readline() if not data: break print(data, end='') except Exception as e: print(f"Error executing command: {command}. Error: {e}") def build_and_release(self): for command in self.commands: self.__run_command(command) if __name__ == "__main__": bar = BuildAndRelease() bar.build_and_release()