Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interactive Batch File

Tags:

batch-file

dos

How to proceed with an interactive batch file?

Eg.,

DO you want to continue? [y/n]

If 'y' Goto Label1

Else Goto Label2

Thanks

like image 553
Bharani Avatar asked Sep 27 '26 05:09

Bharani


2 Answers

You can use the SET command. The following is the DOS command equivalent of the pseudo code you have above:

set /p choice=Do you want to continue? [y/n]
if '%choice%'=='Y' goto label1
goto label2
like image 159
EggyBach Avatar answered Sep 28 '26 22:09

EggyBach


Using the choice command, you can specify a set of valid characters and a message:

choice /C YN /M "Do you want to continue?"
if errorlevel 2 goto labelno
if errorlevel 1 goto labelyes
like image 20
Timbo Avatar answered Sep 28 '26 20:09

Timbo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!