Files
Autumn-27 159c587c2e fix(script): start.bat 改用 CRLF 并切 UTF-8 代码页
start.bat 之前是 LF 换行。cmd.exe 解析批处理按字节偏移边读边执行,
只认 \r\n,全 LF 时会读串行,表现为 goto loop 被截断成 'oop'、
"75"( 不是内部或外部命令、: 运算符不存在等一连串报错,脚本根本跑不起来。

同时文件是 UTF-8 无 BOM,中文控制台默认 GBK(936),注释和 echo 全是乱码。

- 顶部加 chcp 65001,中文提示正常显示(artex 本身输出也是 UTF-8)
- 新增 .gitattributes:*.bat 钉 eol=crlf、*.sh 钉 eol=lf,
  避免在 Linux 上编辑或重新 checkout 后又被打回 LF
2026-09-12 05:32:09 -04:00

55 lines
1.6 KiB
Batchfile
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
@echo off
rem 控制台切 UTF-8,否则本文件里的中文在 GBK 终端下是乱码。
chcp 65001 >nul 2>&1
rem ARTEX 守护启动脚本(Windows)
rem
rem 用法:
rem start.bat 前台运行(Ctrl-C 停止)
rem start.bat -addr :9000 额外参数原样透传给 artex
rem
rem 它只做一件事:把 artex.exe 跑起来,进程退出后按退出码决定要不要再拉起。
rem
rem 0 用户正常停止 -> 退出循环
rem 75 程序请求重启 -> 立刻重跑(页面点了"一键更新"或"回滚")
rem 其他 崩溃 -> 退避后重跑(1->2->4…最多 60 秒)
rem
rem 下载、SHA256 校验、换装都不在这里,全部由 artex 自己在启动时完成
rem (selfupdate 包)。脚本保持傻瓜化,详见 start.sh 顶部的说明。
setlocal enabledelayedexpansion
cd /d "%~dp0"
set "BIN=artex.exe"
if not exist "%BIN%" (
echo [artex] 找不到可执行文件 %BIN% 1>&2
exit /b 1
)
set "RESTART_CODE=75"
set "MAX_DELAY=60"
set /a delay=1
:loop
"%BIN%" %*
set "code=!ERRORLEVEL!"
if "!code!"=="0" (
echo [artex] 正常退出
exit /b 0
)
if "!code!"=="%RESTART_CODE%" (
rem 更新/回滚已就绪:重跑后 artex 会在启动时完成换装。
echo [artex] 请求重启(应用新版本)…
set /a delay=1
goto loop
)
echo [artex] 异常退出 ^(code=!code!^),!delay!s 后重启 1>&2
rem timeout 在被重定向的控制台里会失败,用 ping 兜底(延时 N 秒需要 N+1 次)。
set /a pings=!delay!+1
ping -n !pings! 127.0.0.1 >nul 2>&1
set /a delay=!delay!*2
if !delay! gtr %MAX_DELAY% set /a delay=%MAX_DELAY%
goto loop