Home > Windows > How to create a choice like command in a batch file?

How to create a choice like command in a batch file?

There used to be a windows command called choice, which takes yes or no for an answer. Recently I was making a batch file and tried the same command again but to my surprise found that it was not available.

So I didn’t implement that part. But later I found out another way and probably a better way to implement this behavior using the ‘set’ command.

For eg: if you wanna ask a question like, please enter your name, this is how we would do it…

set /p NameVar=”Please enter your name? “

When you press enter you will be asked for your name and on command completion your name will be stored in NameVar.

You can print out the value using…

echo %NameVar%

Advertisements
Categories: Windows Tags: ,
  1. JannoT
    December 20, 2008 at 8:48 pm

    What a clever solution. (Y) Keep up the good work!

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: