简体   繁体   中英

Batch command how to make a list for set /p

I am trying to make a batch script that asks for user input. The user input should be limited to certain words. If the user enters any other words than eg (eng, ger, fra) the user will get an echo saying something like "Please enter a language".

I also want to store the user input as a variable for further use in the batch file.

What I have so far is:

:Get_ISOlanguage
set "ISOlanguage="
set /p ISOlanguage=Enter subtitle language in ISO 639-2 standard abbreviation:
if not defined ISOlanguage echo You must enter a value. Try again.&goto Get_ISOlanguage

Now how can i list all the accepted words and make these words the only accepted words for the input?

The list of word is very long and I probably don't need to include it here.

get the list into a file and compare your input with that file:

:Get_ISOlanguage
set "ISOlanguage="
set /p "ISOlanguage=Enter subtitle language in ISO 639-2 standard abbreviation: "
find /i "%ISOlanguage%" ISO6392.txt >nul || (echo wrong input & goto :Get_ISOlanguage)

To create the file, I copied the list from here to a temp file and extracted the codes with for /f "delims=- " %i in (ISO-list.txt) do @echo %i)>ISO6392.txt (one-time-task)

Notes:

I used set /p "var=prompt: " syntax for clear definition of what is displayed (note the space, which is part of the prompt)

>nul redirects command output to NUL (nirvana). You probably don't want to see it on the screen.

|| works as "if previous command (find) failed, then" (opposite would be && )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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