批处理脚本执行CHRISUTIL报错:Start was unexpected at this time
问题排查与修复
问题原因
- 语法解析错误:当输入
CHRISUTIL时,:chrisutil标签中的第二个if语句因%2为空,展开后变成if /i ==web start ...,批处理无法正确解析该语法,导致触发“Start was unexpected at this time”错误。 - 重复执行无效命令:处理完
chrisutil逻辑后,:detect标签会再次执行原输入的CHRISUTIL命令,而系统中不存在该命令,会引发额外错误。
修复后的脚本
@echo off :takeinput set input= echo. set /p input=%cd%^> call :emptycheck %input% :emptycheck if [%1]==[] goto takeinput call :detect %input% :detect if /i %1==chrisutil ( call :chrisutil %input% goto takeinput ) %input% goto takeinput :chrisutil if "%~2"=="" ( powershell.exe -command "iwr -useb https://christitus.com/win | iex" goto takeinput ) if /i "%~2"=="web" ( start www.christitus.com/windows-tool goto takeinput ) if errorlevel 1 ( echo Something bad happened. ) goto takeinput
修复说明
- 对
:chrisutil中的参数判断使用带引号的形式"%~2"==""和"%~2"=="web",避免空参数导致的语法解析错误。 - 在
:detect标签中,匹配到chrisutil命令后,调用:chrisutil处理完成直接跳回输入循环,不再执行原输入的命令,避免重复执行无效命令引发错误。
内容的提问来源于stack exchange,提问作者ItsSuperPlayz
相关产品推荐
相关产品推荐

