From 1597da838e4e17f65bf1f28ad99a59f42ec77db1 Mon Sep 17 00:00:00 2001 From: MeiFei Date: Thu, 11 Sep 2025 15:11:46 +0800 Subject: [PATCH] fix os.system --- ci/access_control_test.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/ci/access_control_test.py b/ci/access_control_test.py index cdd927ac..7f399152 100644 --- a/ci/access_control_test.py +++ b/ci/access_control_test.py @@ -1,4 +1,6 @@ import os +import subprocess +import shlex from pathlib import Path @@ -77,15 +79,24 @@ def filter_exec_ut(raw_txt_file): def acquire_exitcode(command): - exitcode = os.system(command) - real_code = os.WEXITSTATUS(exitcode) - return real_code - + """不使用 shell 的更安全版本(推荐用于处理用户输入)""" + try: + # 将命令字符串分割成参数列表 + args = shlex.split(command) + result = subprocess.run(args, capture_output=True) + return result.returncode + except FileNotFoundError: + print(f"命令未找到: {command}") + return 127 + except Exception as e: + print(f"执行命令时发生错误: {e}") + return 1 # ============================= # UT test, run with pytest # ============================= + class UTTest: def __init__(self): self.base_dir = Path(__file__).absolute().parents[1] -- Gitee