subprocess module call
Medium
- Category
- Dangerous Code Execution
- Content
print(f"⚠️ 检测到缺少库 '{package_name}',正在自动安装...") try: # 使用 sys.executable 确保安装到当前运行的 Python 环境中 subprocess.check_call([sys.executable, "-m", "pip", "install", package_name]) print(f"✅ 库 '{package_name}' 安装成功!") except subprocess.CalledProcessError: print(f"❌ 安装失败,请手动运行: pip install {package_name}")- Confidence
- 95% confidence
- Finding
- The script executes an external process to run pip installation at runtime, which expands its capabilities beyond document generation into package management and code acquisition. Even though the package name is hard-coded here, invoking pip automatically can fetch and install code from package indexes without explicit user approval, creating supply-chain and unexpected-execution risk.
