Pattern: Windows Python subprocess 调用 bash 路径翻译失败
发现日期: 2026-07-28 来源: smoke-test.py 中 startup-check.sh 长期误判FAIL 严重度: 🔴 高
触发条件
# Windows Python 中
TOOLS_DIR = Path("C:/Users/xinzh/.openclaw/tools/core")
subprocess.run(["bash", str(TOOLS_DIR / "startup-check.sh")])
# → /bin/bash: C:Usersxinzh.openclawtoolscorestartup-check.sh: No such file or directory
# → RC=127
根因三重
str(Path)在 Windows 上输出反斜杠 → bash 吃掉反斜杠Path.as_posix()输出C:/Users/...→ Git Bash 不认识C:前缀(需要/c/)/c/前缀路径 → Windows Pythonos.path.exists()返回 False
修复
# ✅ 使用 shell=True + 原生 Windows 路径
subprocess.run(f'bash "{TOOLS_DIR / "script.sh"}"', shell=True, ...)
预防规则
- Windows + Python + bash 的三重环境组合:优先
shell=True - 所有Python→bash的调用路径测试必须在Windows上实际跑
- CI中增加Windows专项测试