@echo off rem ============================================================================ rem 观澜 start.bat rem 2026-09-16 用户令: 启动观澜系统时"弹出的命令窗口"改为不弹出方式。 rem 2026-09-16 用户令二: **把 VBScript 替换掉** —— 原先无窗口启动靠 start_hidden.vbs rem (WScript.Shell.Run 窗口样式 0)。现改为直接用 pythonw.exe(无控制台子系统的 rem 解释器) 跑启动器: 不经过 Windows 脚本宿主, WSH 被组策略禁用/未安装的 rem 服务器上照样能用。 rem rem 默认 (双击本文件) : pythonw.exe 无窗口起服务 + 等就绪 + 自动开浏览器。 rem ★ .bat 本身是控制台程序, 双击时 Windows 必定先开一个窗口; 本脚本会让它 rem 在零点几秒内自己关掉 (脚本内无法消除这个闪窗)。要**完全不闪窗**: rem 用安装时生成的 `启动观澜.lnk`(目标 = .venv\Scripts\pythonw.exe), rem 它不经过 cmd.exe, 一个窗口都不会出现。 rem start.bat console : 前台模式 (旧行为) —— 在当前窗口里跑 serve 并实时打印日志, rem 只在排障时用; 关掉这个窗口等于停掉 serve。 rem start.bat help : 说明。 rem rem 为什么分开: 各组件服务本来就是 DETACHED_PROCESS 起的 (不弹窗), 唯一会弹的就是 rem "在控制台里前台跑 guanlan.py serve" 这件事本身。排障又确实需要看见实时输出, rem 所以保留一个显式的 console 档, 而不是把日志彻底藏掉。 rem ============================================================================ chcp 65001 >nul set PYTHONUTF8=1 cd /d "%~dp0" if /i "%~1"=="help" goto help if /i "%~1"=="console" goto console if /i "%~1"=="-c" goto console if not exist ".venv\Scripts\pythonw.exe" ( echo [X] Not installed yet: .venv\Scripts\pythonw.exe not found echo Run install.bat first. pause exit /b 2 ) if not exist "scripts\guanlan_start_hidden.py" ( echo [X] Missing launcher: scripts\guanlan_start_hidden.py echo The package is incomplete - re-extract it ^(check.bat reports this too^). pause exit /b 3 ) rem 无窗口启动: pythonw.exe 无控制台子系统, 运行期间不出现任何窗口。 rem (/min 是双保险; 启动器起完 serve 就退出, 不挂窗口。) start "" /min ".venv\Scripts\pythonw.exe" "scripts\guanlan_start_hidden.py" exit /b 0 :console if not exist ".venv\Scripts\python.exe" ( echo [X] Not installed yet: .venv\Scripts\python.exe not found echo Run install.bat first. If install printed errors, send that screen back echo instead of continuing - the server cannot start without .venv. pause exit /b 2 ) echo [i] Foreground mode - this window stays open and shows live logs. echo Close it to stop the server; for no-window start just run start.bat with no argument. echo. ".venv\Scripts\python.exe" guanlan.py serve if errorlevel 1 ( rem serve exits 1 in two different cases: the gateway never came up, or the gateway is rem up with at least one degraded module, e.g. Ollama not running. Probe healthz to tell rem them apart, otherwise a working server gets reported as "did not start". ".venv\Scripts\python.exe" -c "import urllib.request,sys; sys.exit(0 if urllib.request.urlopen('http://127.0.0.1:28084/healthz',timeout=6).status==200 else 1)" 2>nul if errorlevel 1 ( echo. echo [X] Gateway did not come up ^(reason above^). Not opening the browser - echo a "site cannot be reached" page would look like a network problem. echo See logs\gateway.log pause exit /b 1 ) echo. echo [!] Gateway is up, but at least one module is degraded ^(the [DOWN] lines above^). echo Usual cause: local Ollama is not running or has no models pulled, which only echo disables the Q^&A / local-review pages. Every other page works. echo Details: logs/ for the degraded module. ) start "" http://127.0.0.1:28084/ echo. echo [i] Ops console - stop/start services, rebuild, clear products: echo http://127.0.0.1:28084/ops echo It stays available while component services are stopped (only the gateway must be up); echo buttons follow real state and the backend refuses impossible actions (HTTP 409). exit /b 0 :help echo Usage: echo start.bat no-window start (default): pythonw + browser (this cmd window blinks ~0.2s) echo <> 启动观澜.lnk - zero window at all (created by install; target = pythonw.exe) echo start.bat console foreground start with live logs (troubleshooting) echo stop.bat stop everything echo check.bat self-check echo Logs: logs\serve.log (no-window mode), logs\start_hidden.log (launcher trace) exit /b 0