"如果"声明" goto"错误

时间:2016-05-04 13:05:40

标签: windows batch-file cmd

编辑:我发现了问题。我的输入变量和'如果'变量是不同的,我改变之后忘了改变其中一个。

所以我遇到了我的代码问题。

错误;

"goto installupdate" was unexpected at this time

这一切都适用于

if %updatech%==Y goto iu
if %updatech%==y goto iu
if %updatech%==N goto noupdate
if %updatech%==n goto noupdate

我不确定自己做错了什么。任何人都知道我的代码中出了什么问题?

代码:

REM检查安装程序的更新

:updatecheck
bitsadmin.exe /transfer "updatecheck" "http://serverse.playat.ch/overtone/update.txt" "%temp%\overtoneupdate.txt"
set /p versioncompare=<"%temp%\overtoneupdate.txt"
del "%temp%\overtoneupdate.txt"
cls
if %currentbuild% == %versioncompare% goto noupdate
set /p updateyn=New version found! Would you like to update? [Y/N]:
if %updatech%==Y goto iu
if %updatech%==y goto iu
if %updatech%==N goto noupdate
if %updatech%==n goto noupdate
goto updatecheck

:iu
bitsadmin.exe /transfer "update" "http://serverse.playat.ch/overtone/%versioncompare%update.bat" "%cd%\update.bat"
echo %versioncompare%>upvers.txt
update.bat
exit

:noupdate
 cls
 goto install

1 个答案:

答案 0 :(得分:0)

在以下代码行中,您要设置一个名为updateyn的变量,但检查名为updatech的变量。

set /p updateyn=New version found! Would you like to update? [Y/N]:
if %updatech%==Y goto iu

这总是空的,所以失败了,因为它归结为

if ==Y goto iu

这是无效的语法。

除了修复变量名称之外,您还应该考虑用户只需按Enter键的情况(这会导致同样的问题)。

您可以通过在变量

周围放置一个已知字符串来解决这个问题
    if x%updateyn%x==xYx goto iu

例如。

相关问题