Here is my code:
@echo off
Title Search Providers
:home
Echo [1] Google
Echo [2] Bing
Echo [3] Yahoo
Set /p udefine
If %udefine%== 1 start www.google.com
If %udefine%== 2 start www.bing.com
If %udefine%== 3 start www.yahoo.com
I really don't understand because most of the batch files I make close like that too.
The batch script closes once it's done because that's how batch scripts function. Once a script has no more code to run, the window closes. If you want to keep the window open, you can use the
pausecommand or run the script from the command prompt instead of double-clicking it.You are missing a
=at the end of theset /pcommand, which is what is causing the "the syntax of the command is incorrect" error.It is generally considered a good idea to use quotes, brackets, or some other character when comparing strings, just in case the user hit
enterwithout typing anything. Like Serenity mentioned, if you have an option to use thechoicecommand, use that, since it's more robust.It's also considered good practice to have
""immediately after astartcommand, just in case you need to start something that needs to be wrapped in quotes;startconsiders the first thing in quotes it encounters to be the window title and then everything after that is the command. As you can imagine, this has the potential to break your code.And so, in summary: