From e9f810d7ff18e4e9e993123f14d5428defe7c5c2 Mon Sep 17 00:00:00 2001 From: EMRG Evolution Date: Thu, 13 Aug 2026 09:36:05 +0800 Subject: [PATCH] emrg: installer shows stop-emrg.cmd output on failure (rant 2026-08-13T09:24:37) --- packaging/make-installer.sh | 21 +++++++++++++++++++-- tests/test_installer_stop.py | 7 ++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/packaging/make-installer.sh b/packaging/make-installer.sh index 760ed04f..49bfa7fa 100755 --- a/packaging/make-installer.sh +++ b/packaging/make-installer.sh @@ -384,14 +384,31 @@ function PrepareToInstall(var NeedsRestart: Boolean): String; var ResultCode: Integer; StopScript: string; + LogFile: string; + LogText: string; begin Result := ''; ExtractTemporaryFile('stop-emrg.cmd'); StopScript := ExpandConstant('{tmp}\\stop-emrg.cmd'); - if Exec(ExpandConstant('{cmd}'), '/c "' + StopScript + '"', '', SW_HIDE, ewWaitUntilTerminated, ResultCode) then + // R125: rant 2026-08-13T09:24:37 — stop-emrg.cmd 输出重定向到日志,失败时 + // 直接展示日志内容(列出杀不掉的进程),宿主不再需要手动跑诊断。 + // cmd 引号嵌套:外层 /c "...",内层脚本路径用双引号包裹,重定向在外、 + // 仍在内层引号外(SW_HIDE 隐藏窗口后 stdout/stderr 经 > log 2>&1 落盘)。 + LogFile := ExpandConstant('{tmp}\\stop-emrg.log'); + if Exec(ExpandConstant('{cmd}'), '/c ""' + StopScript + '" > "' + LogFile + '" 2>&1"', '', SW_HIDE, ewWaitUntilTerminated, ResultCode) then begin if ResultCode <> 0 then - Result := 'EMRG could not stop all running processes (stop-emrg.cmd exit code ' + IntToStr(ResultCode) + '). Please close EMRG (GUI/TUI) and retry the install, or restart the computer and retry (a helper process such as the bundled Git may still hold a file lock).'; + begin + LogText := ''; + if FileExists(LogFile) then + LogText := LoadStringFromFile(LogFile); + if Length(LogText) > 2000 then + LogText := Copy(LogText, 1, 2000); + if LogText <> '' then + Result := 'EMRG could not stop all running processes (stop-emrg.cmd exit code ' + IntToStr(ResultCode) + '). Details from stop-emrg.cmd:' + #13#10 + #13#10 + LogText + #13#10 + #13#10 + 'Please close EMRG (GUI/TUI) and retry the install, or restart the computer and retry (a helper process such as the bundled Git may still hold a file lock).' + else + Result := 'EMRG could not stop all running processes (stop-emrg.cmd exit code ' + IntToStr(ResultCode) + '). Please close EMRG (GUI/TUI) and retry the install, or restart the computer and retry (a helper process such as the bundled Git may still hold a file lock).'; + end; end else Result := 'EMRG could not run the process-stop helper (stop-emrg.cmd). Please close EMRG (GUI/TUI) and retry the install, or restart the computer and retry.'; diff --git a/tests/test_installer_stop.py b/tests/test_installer_stop.py index 81a9ea0f..e6ec0deb 100644 --- a/tests/test_installer_stop.py +++ b/tests/test_installer_stop.py @@ -118,7 +118,12 @@ def test_make_installer_iss_has_prepare_to_install(): assert "ExtractTemporaryFile('stop-emrg.cmd')" in content # 单文件:只提取/执行 stop-emrg.cmd(stop-git.ps1 已删除) assert "ExtractTemporaryFile('stop-git.ps1')" not in content - assert "/c \"' + StopScript + '\"" in content + # R125: rant 2026-08-13T09:24:37 — 输出重定向到 {tmp}\stop-emrg.log(2>&1), + # 失败时 LoadStringFromFile 读日志展示杀不掉的进程,不再让宿主手动跑诊断 + assert '/c ""\' + StopScript + \'" > "\' + LogFile + \'" 2>&1"' in content + assert "LoadStringFromFile(LogFile)" in content + assert "Length(LogText) > 2000" in content + assert "Details from stop-emrg.cmd:" in content assert "SW_HIDE" in content # 批处理执行不弹控制台窗口(#592 纪律) # rant 2026-08-11T17:56:25:中止消息含重启兜底引导(杀不掉时宿主可重启后重试) assert "restart the computer" in content