From ec921dd89779075130a888e4cabf2d260a7e4b09 Mon Sep 17 00:00:00 2001 From: Belugary <53219544+Belugary@users.noreply.github.com> Date: Tue, 5 May 2026 22:47:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20monitor=5Fweb=20=E7=94=A8=20webbrowser.o?= =?UTF-8?q?pen=20=E6=9B=BF=E4=BB=A3=20cmd.exe=20=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=E8=B7=A8=E5=B9=B3=E5=8F=B0=E5=BC=80=E6=B5=8F=E8=A7=88=E5=99=A8?= =?UTF-8?q?=20(#70)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 之前 main() 启动 HTTP server 后用 `os.system('cmd.exe /c start ')` 自动开浏览器, 这条命令在非 Windows 平台 cmd.exe 不存在, os.system 返回 非零退出码 (不抛异常, 外层 except 抓不到), 调用静默失败 → 自动开浏览器 功能在 Linux / macOS 完全失效; 同时 shell 会把 `cmd.exe: command not found` 写到终端 stderr 干扰用户. 改用 Python 标准库 webbrowser.open(), 跨平台自动选默认浏览器, 无新增依赖. --- monitor_web.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/monitor_web.py b/monitor_web.py index cd5f276..ec5f275 100644 --- a/monitor_web.py +++ b/monitor_web.py @@ -2096,7 +2096,8 @@ def main(): print("Ctrl+C 停止\n", flush=True) try: - os.system(f'cmd.exe /c start http://localhost:{PORT}') + import webbrowser + webbrowser.open(f'http://localhost:{PORT}') except Exception: pass