From dc2f8a299f490e0bcc479fc3aa5bbea73c08c5bb Mon Sep 17 00:00:00 2001 From: dongchangxi <458593490@qq.com> Date: Fri, 10 Jan 2025 23:35:11 +0800 Subject: [PATCH] 1 --- yj_local_build/main_step1.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/yj_local_build/main_step1.py b/yj_local_build/main_step1.py index 08f0a26..a369ca8 100644 --- a/yj_local_build/main_step1.py +++ b/yj_local_build/main_step1.py @@ -103,7 +103,29 @@ def detect_markers(psid, pid): {textpicCmd} -save "{os.path.join(config["workdir"], pid, f"{pid}.rcproj")}" -quit' print(cmd) cmd = shlex.split(cmd) - res = subprocess.run(cmd) + #res = subprocess.run(cmd) + # 使用 Popen 来执行命令 + process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + # 检查命令是否执行完毕 + while True: + return_code = process.poll() # 获取进程的退出码,None 表示进程仍在运行 + if return_code is not None: + print("Command finished with return code:", return_code) + break + print("Command is still running...") + time.sleep(1) # 每秒检查一次进程状态 + + # 获取命令的输出 + stdout, stderr = process.communicate() + + # 打印输出结果 + if return_code == 0: + print("Command executed successfully.") + print(f"Output: {stdout.decode()}") + else: + print(f"Command failed with return code {return_code}") + print(f"Error: {stderr.decode()}") time.sleep(3) fix_region() print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} pid: {pid} 定位点检测完成, 共费时{diff_time(start_time)}')