Solved Batch Spaces In Input

September 11, 2012 at 00:40:53
Specs: Windows Vista
Batch Spaces in Input??
Help! does anyone know how to make it possible to add spaces in input?
for example

echo oh no a troll appeared!
set /p input=
if /i %input%==hit troll with axe goto GAMEOVER

if i type "hit troll with axe" it doesnt work!, how do i make it posible to add spaces?
also the "If NOT defined" command doesnt work for me what am i doing wrong?
i typed in

echo Oh no a Troll!!
set /p input=
if /i %input%==hit troll with axe goto GAMEMOVER
if not defined input (
echo invalid
goto cave
but it wont work!, it just skips to the next part, help please!
i hope i explained clearly, thanks for any feedback


See More: Batch Spaces In Input

Report •

September 11, 2012 at 01:53:27
set/p WILL take spaces:

C:\TEMP\-\11>set/p z=one tqo five
one tqo fiveC:\TEMP\-\11>set/p z=
one two

C:\TEMP\-\11>echo %z%
one two

Life is too important to be taken seriously.


Report •

September 11, 2012 at 17:30:23
✔ Best Answer
two things i noticed. whenever you use "set /p", you should clear the variable imm. before the set, otherwise it will retain any prior content, and not be "" if the user hits a null-entry. Second, you probably need quotes around the var when testing since it may contain spaces. Here's the gist:
set input =
set /p input=
if /i "%input%"=="hit troll with axe" goto GAMEMOVER

Report •

September 12, 2012 at 00:00:47
Thanks Alot it really helped!, but M2 could you please explain what all those lines of codes does?, i dont quite understand..


Report •

Related Solutions

Ask Question