1

To clarify upon the title: I'm creating a batch file to use the CHOICEcommand and based on the input key I plan to call a batch file containing the server to join and what program to do it with.

The problem is that when run the command loops its output infinitely in the cmd window. I am looking for a way to display the /M, not looping the output. Ive tried @ECHO off but that results in the /M not being displayed.

My research thus far is My Batch File keeps looping, but why? http://ss64.com/nt/choice.html

and a few wikis about basic commands.

My code thus far is

CD C:\Users\Chris\Desktop
CHOICE /C 12 /M Select [1] Private server or [2] Other
IF errorlevel 2 call "other.bat"
IF errorlevel 1 call "private.bat"

the original before i attempted any of the fixes ive found was

CHOICE /C 12 /M Select [1] Private server or [2] Other
IF errorlevel 2 call C:\Users\Chris\Desktop\other.bat
IF errorlevel 1 call C:\Users\Chris\Desktop\private.bat

I have two empty batch files on the desktop at the above paths, so that the files are technically there, but the output of either of the above is looped with no way to use the input (i.e. pressing 1 or 2 doesn't do anything and it continues the loop).

Looping

Andreas
  • 5,393
  • 9
  • 44
  • 53
cdog1019
  • 9
  • 4
  • What command is getting looped? Have you tried starting the batch-files instead of calling them? – Dennis van Gils Dec 14 '15 at 20:44
  • `if errorlevel 1` means if `%ERRORLEVEL%` is greater than or equal to 1. You either need `else if` or `if %ERRORLEVEL% equ 1`. – rojo Dec 14 '15 at 20:52
  • `CHOICE /C 12 /M "Select [1] Private server or [2] Other"` (missing double quotes). – JosefZ Dec 14 '15 at 20:54
  • https://i.gyazo.com/3d8980c840c01235f5fb405ab0c9837c.png in reply to dennis this is the command looping, and at the moment the targeted batch files are empty. To rojo, would that mean i add percentages and remove the als from equals? as for josefZ i added quotation to either method with no sucess. Denni – cdog1019 Dec 14 '15 at 21:34
  • Possible duplicate of [My Batch File keeps looping, but why?](http://stackoverflow.com/questions/19047442/my-batch-file-keeps-looping-but-why) – Huseyin Yagli Feb 08 '17 at 20:00

1 Answers1

1

Save your file as something other than choice.bat

When choice is reached, it executes the batch, not the choice command hence the looping.

And you definitely need the quotes around the string following /m

Magoo
  • 77,302
  • 8
  • 62
  • 84