简体   繁体   English

我的批处理脚本不起作用,我不知道为什么

[英]My batch script is not working, I have no idea why

I've spent my recent hours researching batch scripting and compiling my own program using lua, and batch.我最近花了几个小时研究批处理脚本并使用 lua 和批处理编译我自己的程序。 One of my batch files isn't working properly and I have 0 idea why.我的一个批处理文件无法正常工作,我不知道为什么。 I have edited the script a bit since then but not anything that would change how it works.从那时起,我对脚本进行了一些编辑,但没有任何改变它的工作方式的东西。

This batch script is making you enter a password when you start it up.此批处理脚本使您在启动时输入密码。 When I answer with the correct password it will say ACCESS GRANTED.当我用正确的密码回答时,它会说 ACCESS GRANTED。 And when entering it wrong it should say ACCESS DENIED.当输入错误时,它应该说访问被拒绝。 But what is happening instead is that when I enter the wrong password, it says ACCESS GRANTED.但是发生的事情是,当我输入错误的密码时,它会显示 ACCESS GRANTED。 I cannot seem to find why this doesn't work.我似乎无法找到为什么这不起作用。

@echo off
color A
set password=YOUR PASSWORD HERE

:start
cls
echo Welcome!
echo Please input password:
set /p passwordinput=

if %passwordinput%==%password% (
cls
color 2
echo ACCESS GRANTED!
timeout /t -1
goto access
) else (
cls
color C
echo ACCESS DENIED
echo TRY AGAIN
timeout /t -1
cls
color a
goto start
)

:access
cls
pause

You should always use quotes in if string compares, else you got syntax errors when one string contains spaces.如果字符串比较,则应始终使用引号,否则当一个字符串包含空格时会出现语法错误。

if "%passwordinput%" == "%password%" (
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM