You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

批处理脚本运行异常,任意输入均提示Invalid Option,无法定位错误原因

你代码的核心问题是批处理set语法使用错误:批处理中给变量赋值时,等号两侧不能有多余空格,你写的set INPUT = 、SET /p INPUT = Do you want to update all[Y/N]? %=% 里等号左侧和变量名之间多了空格,实际生成的变量名是带空格的INPUT ,你后续判断用的%INPUT%是无空格的变量名,永远匹配不到输入的Y/N,所以会一直输出Invalid Option。

另外你代码里还有个笔误:更新提示的Udating拼写错误,正确为Updating。

修正后的完整代码如下:

@ECHO OFF
::This script will check if there are any available updates for software via Winget and will let you update all
ECHO Searching for updates...
ECHO =======================================================================
winget upgrade
ECHO =======================================================================
:ask
set INPUT=
SET /p INPUT=Do you want to update all[Y/N]? %=%
IF /i "%INPUT%" == "Y" GOTO yes
IF /i "%INPUT%" == "N" GOTO no
ECHO Invalid Option
GOTO ask
:yes
ECHO Updating all available packages...
winget upgrade --all
GOTO end
:no
GOTO end
:end
cmd /k

内容的提问来源于stack exchange,提问作者Kerem Ibrahimoglu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.23 14:24:01