From b70cdecff7caeb0050cbc3bfa28e3893b7fabf64 Mon Sep 17 00:00:00 2001 From: argszero Date: Mon, 10 Aug 2026 09:39:01 +0800 Subject: [PATCH] =?UTF-8?q?emrg:=20cmd=20launchers=20=E2=80=94=20ASCII-onl?= =?UTF-8?q?y=20REM=20comments=20(CP936=20mojibake,=20host=2001:36:12Z=20no?= =?UTF-8?q?te)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/emrg.cmd | 10 +++++----- bin/emrgd.cmd | 20 ++++++++++---------- bin/stop-emrg.cmd | 14 +++++++------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/bin/emrg.cmd b/bin/emrg.cmd index 7fba601e..ab9ece40 100644 --- a/bin/emrg.cmd +++ b/bin/emrg.cmd @@ -1,17 +1,17 @@ @echo off -REM EMRG launcher — installed at %USERPROFILE%\.emrg\install\bin\emrg.cmd -REM Phase 4 installer (rant #12) §2: -REM - R60: Windows git lives in install\git\ — PATH needs git\cmd + git\mingw64\bin. +REM EMRG launcher -- installed at %USERPROFILE%\.emrg\install\bin\emrg.cmd +REM Phase 4 installer (rant #12) section 2: +REM - R60: Windows git lives in install\git\ -- PATH needs git\cmd + git\mingw64\bin. REM - R35: %~dp0 under a .lnk shortcut resolves to the .cmd's real location. REM - R13: PYTHONPATH includes source\ (parent of the emrg package). -REM - R61: source\ is read-only — PYTHONDONTWRITEBYTECODE (zero-write acceptance). +REM - R61: source\ is read-only -- PYTHONDONTWRITEBYTECODE (zero-write acceptance). set SOURCE=%~dp0 set DIR=%SOURCE:~0,-1% set PREFIX=%DIR%\.. set PATH=%DIR%;%PREFIX%\git\cmd;%PREFIX%\git\mingw64\bin;%PATH% set PYTHONPATH=%PREFIX%\source;%PREFIX%\lib;%PYTHONPATH% set PYTHONDONTWRITEBYTECODE=1 -REM R90: python.exe 复制品在 bin/,DLL 在 python-dist/ → loader 找不到 → 用 python-dist 里的 exe(与 DLL 同目录) +REM R90: python.exe copy lives in bin/, DLLs in python-dist/ -> loader would miss them -> use the exe in python-dist (same dir as DLLs) set PYEXE=%DIR%\python-dist\python.exe if not exist "%PYEXE%" set PYEXE=%DIR%\python-dist\python3.13.exe "%PYEXE%" -m emrg %* diff --git a/bin/emrgd.cmd b/bin/emrgd.cmd index 7e58c88c..283b7ed2 100644 --- a/bin/emrgd.cmd +++ b/bin/emrgd.cmd @@ -1,6 +1,6 @@ @echo off -REM EMRG daemon launcher — installed at %USERPROFILE%\.emrg\install\bin\emrgd.cmd -REM Phase 4 installer (rant #12) §2 — same structure as bin\emrg.cmd; entry is +REM EMRG daemon launcher -- installed at %USERPROFILE%\.emrg\install\bin\emrgd.cmd +REM Phase 4 installer (rant #12) section 2 -- same structure as bin\emrg.cmd; entry is REM the server package. GUI main.js spawns this path (R36 shell:true, R66 windowsHide). set SOURCE=%~dp0 set DIR=%SOURCE:~0,-1% @@ -8,17 +8,17 @@ set PREFIX=%DIR%\.. set PATH=%DIR%;%PREFIX%\git\cmd;%PREFIX%\git\mingw64\bin;%PATH% set PYTHONPATH=%PREFIX%\source;%PREFIX%\lib;%PYTHONPATH% set PYTHONDONTWRITEBYTECODE=1 -REM R90: python.exe 复制品在 bin/,DLL 在 python-dist/ → loader 找不到 → 用 python-dist 里的 exe(与 DLL 同目录) -REM 无窗口 daemon:GUI spawn 此脚本时 python.exe(console 子系统)会新开控制台黑窗; -REM 改优先用 pythonw.exe(GUI 子系统,不开窗口)。日志写 ~/.emrg/emrgd.log -REM (RotatingFileHandler),StreamHandler 仅附加,无控制台不影响日志。 +REM R90: python.exe copy lives in bin/, DLLs in python-dist/ -> loader would miss them -> use the exe in python-dist (same dir as DLLs) +REM Windowless daemon: when the GUI spawns this script, python.exe (console subsystem) would open a black console window; +REM prefer pythonw.exe (GUI subsystem, no window). Logs go to ~/.emrg/emrgd.log +REM (RotatingFileHandler); StreamHandler only attaches, no console so logging is unaffected. set PYEXE=%DIR%\python-dist\pythonw.exe if not exist "%PYEXE%" set PYEXE=%DIR%\python-dist\python.exe if not exist "%PYEXE%" set PYEXE=%DIR%\python-dist\python3.13.exe -REM R124: `emrgd.cmd stop` — 优雅关闭 daemon(rant 2026-08-10T08:50:44 安装器预停止): -REM 复用 CLI `emrg server stop`(协议 shutdown → ping-pid SIGTERM 兜底,见 -REM emrg/__main__.py _stop_daemon)。pythonw 无控制台,print 丢弃无害,shutdown 无需 stdout。 -REM 用标签而非括号块,保证 %errorlevel% 在 python 退出后才展开。 +REM R124: `emrgd.cmd stop` - graceful daemon shutdown (rant 2026-08-10T08:50:44 installer pre-stop): +REM reuses the CLI `emrg server stop` (protocol shutdown -> ping-pid SIGTERM fallback, see +REM emrg/__main__.py _stop_daemon). pythonw has no console; dropped prints are harmless, shutdown needs no stdout. +REM uses labels not parenthesized blocks so %errorlevel% expands only after python exits. if /I not "%~1"=="stop" goto :start "%PYEXE%" -m emrg server stop exit /b %errorlevel% diff --git a/bin/stop-emrg.cmd b/bin/stop-emrg.cmd index 4b0849a3..6553e07e 100644 --- a/bin/stop-emrg.cmd +++ b/bin/stop-emrg.cmd @@ -1,17 +1,17 @@ @echo off -REM stop-emrg.cmd — gracefully stop EMRG GUI/TUI/daemon before the installer +REM stop-emrg.cmd -- gracefully stop EMRG GUI/TUI/daemon before the installer REM overwrites ~\.emrg\install files (rant 2026-08-10T08:50:44: Inno Setup got -REM stuck at "停止已有进程" because the windowless pythonw daemon holds file locks +REM stuck at "stopping existing processes" because the windowless pythonw daemon holds file locks REM and Inno CloseApplications cannot see it). REM REM Order matters (mirrors bin/emrg-uninstall steps 1a/1b): REM 1. GUI (EMRG.exe): graceful WM_CLOSE first (taskkill without /F), then REM UNCONDITIONAL /F after the ~5s grace window (host 01:27:07Z: long-lived -REM GUI deferred WM_CLOSE past 5s — /F must not be gated on a survivor check) +REM GUI deferred WM_CLOSE past 5s -- /F must not be gated on a survivor check) REM 2. TUI (python.exe -m emrg): command-line filter (wmic, PowerShell REM fallback), excludes the daemon (pythonw.exe -m emrg.server) REM 3. daemon: `emrg server stop` protocol shutdown via the OLD install's CLI -REM (present since #364 — version-safe), emrgd.pid poll (<=10s), then +REM (present since #364 -- version-safe), emrgd.pid poll (<=10s), then REM taskkill /F /PID fallback REM REM Returns 0 when nothing EMRG-related survives; 1 if a process could not be @@ -23,7 +23,7 @@ set "INSTALL=%EMRG_DIR%\install" REM --- 1. GUI: graceful WM_CLOSE, then unconditional /F after the grace window --- REM (host report 2026-08-10T01:27:07Z: a long-lived ~15h GUI session deferred -REM WM_CLOSE past the 5s window — two full script runs did not terminate it +REM WM_CLOSE past the 5s window -- two full script runs did not terminate it REM while a direct `taskkill /IM EMRG.exe` did. => the /F fallback must be REM UNCONDITIONAL after the wait so an old GUI session can never hold the REM installer hostage. When the GUI is not running, the graceful taskkill @@ -64,8 +64,8 @@ if defined DPID taskkill /F /PID %DPID% >nul 2>&1 :verify set "EXIT_CODE=0" tasklist /FI "IMAGENAME eq EMRG.exe" 2>nul | findstr /i "EMRG.exe" >nul && set "EXIT_CODE=1" -REM 括号块内 %-变量 在块解析时展开(set "DPID=" 之后取到旧值/空值)→ 必须用 -REM enabledelayedexpansion 的 !DPID!(运行时展开);if defined 本身是运行时判定。 +REM %-variables inside a parenthesized block expand at parse time (after set "DPID=" they hold the old/empty value) -> must use +REM enabledelayedexpansion !DPID! (runtime expansion); if defined itself is a runtime check. if exist "%EMRG_DIR%\emrgd.pid" ( set "DPID=" for /f "usebackq delims=" %%p in ("%EMRG_DIR%\emrgd.pid") do set "DPID=%%p"