批量要求用户输入

问题描述 投票:0回答:2

我需要批处理代码,如果用户输入 yes goto :yes 如果输入其他内容,请转到:否

这是我的代码

@echo off
title CMD

:main
CLS
set /p input= 
if %input%==yes goto yes
else goto no
goto main

:yes
cls
echo you typed yes
pause>nul
exit

:no
cls
echo you typed something other then yes
pause>nul
exit

但是它不起作用,我怎样才能使它起作用? 到目前为止,如果您输入 yes,它将显示:yes 但如果您输入其他内容,它只会进入空白屏幕。

windows batch-file cmd
2个回答
1
投票

您的

()
中需要一些
IF/ELSE

试试这个:

@echo off
title CMD

:main
CLS
set /p input= 
if %input%==yes (
    goto yes
) else (
    goto no
)
goto main

:yes
cls
echo you typed yes
pause>nul
exit

:no
cls
echo you typed something other then yes
pause>nul
exit

0
投票

你可以这样做:

@echo off
title CMD

:main
CLS
set /p input= 
if %input%==yes goto yes
else(if(%input%==no)):goto no
goto main

:yes
cls
echo you typed yes
pause>nul
exit

:no
cls
echo you typed no
pause>nul
exit
© www.soinside.com 2019 - 2024. All rights reserved.