How do I request and receive user input in a .bat and use it to run a certain program?

前端 未结 9 1912
温柔的废话
温柔的废话 2020-12-23 14:37

This is what I have so far

@echo off
:Ask
echo Would you like to use developer mode?(Y/N)
set INPUT=
set /P INPUT=Type input: %=%
If %INPUT%==\"y\" goto yes          


        
9条回答
  •  情话喂你
    2020-12-23 14:50

    I have improved batch file with yes or no prompt. If user enter any character except y and n , then it will again prompt user for valid input. It Works for me.

        @echo off
    
        :ConfirmBox 
            set /P c= Are you sure want to contine (y/n)?
    
        if /I "%c%" EQU "Y" (
        goto :FnYes 
        ) else if /I "%c%" EQU "N" ( 
        goto :FnNo
        ) else ( 
        goto :InValid 
        )
    
    
    :FnYes
         echo You have entered Y
         goto :END
    
    :FnNo
         echo You have entered N
         goto :END
    
    :InValid
         echo Invalid selection. Enter Y or N
         goto :ConfirmBox
    
    :END
        pause
        exit  
    

    /I in if condition will validate both lowercase and uppercase characters.

提交回复
热议问题