Cmd跳过if语句?

编程入门 行业动态 更新时间:2024-10-28 15:24:07
本文介绍了Cmd跳过if语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我很无聊所以我试图在CMD中创建一个虚拟控制台,它似乎工作正常,直到检查输入并相应地执行命令。 我得到一个显示:的屏幕,你可以输入你要执行的命令,输入正常但是当它检查要执行的命令时,会出现问题。 问题是如果我键入register,它应该转到一个名为:reg的标签,我执行exit命令,该命令只应在我输入exit时执行。 这是我的剧本:

echo off cls :console title命令提示符 cls set / pc =: 如果%c%==退出 (退出) 如果%c%==注册( goto:reg ) :reg title注册一个新账户 cls echo注册 echo。 set / p newName =Username: set / p newPass =Password: cls echo Processing ... > nul超时/ t 3 转到控制台

我尝试了什么: 我试过改变命令和if语句的顺序但看起来第一个命令总是被执行而不管你键入什么。

解决方案

尝试这个,暂停和回声验证:

cls :console title命令提示符 cls set / pc =: echo%c%暂停 如果%c%==退出转到结束 如果%c%==注册转到reg 暂停 :reg title注册一个新账户 cls echo注册 echo。 set / p newName =Username: set / p newPass =Password: cls echo Processing ... > nul timeout / t 3 goto console :end

从所有内容中删除引号,不需要使用brakets

echo off cls :console title命令提示符 cls set / pc =: if%c%== exit exit if%c%== register goto:reg :reg title注册一个新账户 cls echo注册 echo。 set / p newName =Username: set / p newPass =Password: cls echo Processing ... > nul timeout / t 3 goto console

如果是多元的话,你在哪里找到线?和()? 这是一个语法链接: 更强大的批处理文件 - 使用If语句进行分支 [ ^ ] Windows命令行| Shell列表和参考 [ ^ ]

I was bored so I tried to make a virtual console inside CMD and it appears to be working fine up until the point of checking the input and executing a command accordingly. I get a screen that says ": " and there you can type what command you want to execute, and typing works fine but when it goes to check what command to execute, problems occurr. The problem is if I type "register" which should go to a label called :reg, I execute the "exit" command, which should only be executed when I type "exit". Here's my script:

echo off cls :console title Command prompt cls set /p c=": " if "%c%"=="exit" ( exit ) if "%c%"=="register" ( goto :reg ) :reg title Register a new account cls echo Registration echo. set /p newName="Username: " set /p newPass="Password: " cls echo Processing... >nul timeout /t 3 goto console

What I have tried: I've tried changing the order of the commands and if-statements but it appears that the first command always gets executed no matter what you type.

解决方案

Try this, stuck pauses in and echo to verify:

cls :console title Command prompt cls set /p c=": " echo %c% pause if "%c%"=="exit" goto end if "%c%"=="register" goto reg pause :reg title Register a new account cls echo Registration echo. set /p newName="Username: " set /p newPass="Password: " cls echo Processing... >nul timeout /t 3 goto console :end

Remove the quotes from everything and there's no need for brakets

echo off cls :console title Command prompt cls set /p c=: if %c%==exit exit if %c%==register goto :reg :reg title Register a new account cls echo Registration echo. set /p newName="Username: " set /p newPass="Password: " cls echo Processing... >nul timeout /t 3 goto console

Where did you catch that if is multi line ? and with () ? Here is a link for the syntax: More Powerful Batch Files- Branching with "If" statements[^] Windows Command Line |Shell List and Reference[^]

更多推荐

Cmd跳过if语句?

本文发布于:2023-11-24 10:13:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1624795.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:跳过   语句   Cmd

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!