CHOICE no entry fail

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Heinen
Posts: 4
Joined: 11 Apr 2013 00:30

CHOICE no entry fail

#1 Post by Heinen » 11 Apr 2013 00:42

Hello, i'm doing this batch choise option;

Code: Select all

set/p "cho=>"

if %cho%==1 start something.exe
if %cho%==2 start something-else.exe

But if i dont enter anything, and hit enter, i get this error code:

Code: Select all

start was unexpected at this time

I need it to "goto something" instead, anyone know how?

(The best would be to make the BACKSPACE to goto command if possible)

Endoro
Posts: 244
Joined: 27 Mar 2013 01:29
Location: Bozen

Re: CHOICE no entry fail

#2 Post by Endoro » 11 Apr 2013 00:56

Put it in double quotes:

Code: Select all

set/p "cho=>"

if "%cho%"=="1" start something.exe
if "%cho%"=="2" start something-else.exe


Don't know what you mean with "Backspace to command".

Heinen
Posts: 4
Joined: 11 Apr 2013 00:30

Re: CHOICE no entry fail

#3 Post by Heinen » 11 Apr 2013 01:44

Endoro wrote:Don't know what you mean with "Backspace to command".

Sry, bad English, i meant make the backspace key, do a "goto" command in the batch.


The problem was fixed, in a way, i dont get the error.

BUT!
When i press enter without enter anything, it chooses the last chosen number!

So if i first choose 1, hit enter, and then go back and hit enter without enter anything, it chooses 1.
I need it to move on instead.

Endoro
Posts: 244
Joined: 27 Mar 2013 01:29
Location: Bozen

Re: CHOICE no entry fail

#4 Post by Endoro » 11 Apr 2013 02:13

Code: Select all

:loop
set "cho="
set/p "cho=>"

if "%cho%"=="1" start something.exe
if "%cho%"=="2" start something-else.exe
goto:loop

Initialize %cho% with "nothing".

Heinen
Posts: 4
Joined: 11 Apr 2013 00:30

Re: CHOICE no entry fail

#5 Post by Heinen » 11 Apr 2013 02:55

Thnx, got it! :)

Possible to make the backspace do the same thing as enter in this situation?

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: CHOICE no entry fail

#6 Post by Squashman » 11 Apr 2013 05:42

Heinen wrote:Thnx, got it! :)

Possible to make the backspace do the same thing as enter in this situation?

Sure. If you want to remap the keys on your keyboard but then all your programs would respond to the backspace key as enter. I wouldn't suggest that.

Post Reply