if /i %user% crashes

February 3, 2009 at 09:38:41
Specs: win xp 5.1.2600, 3mhz/2 gig
Hi all, why wont this work? This is just the beginning of my code. I guess that it is crashing because of the first %user%, but am not sure why.
Please advise. (I need that at the beginning of the code)

if /i %user% == x set user=o & goto :start
if /i %user% == o set user=x & goto :start

cls & echo. & echo Please select either 'X' or 'O'
set /p user=

cls & echo %user% & pause

See More: if /i %user% crashes

Report •

February 3, 2009 at 23:33:37
Where is %user% being set? If %user% is undefined it will cause the if statement to be invalid, the same will happen if it contains certain characters, mainly |,<,> and &. To avoid this enclose it in double quotes.

if /i "%user%"=="x" set user=o & goto :start

This will cause a similar problem if the strings contains double quotes, but there is a work around for this if needed, using dynamic variables that escape the meaning of the double quotes.

A good way to troubleshoot scripts that close unexpectedly is to run them from the command prompt with echo on so you can see the error that is returned and where the script stops.



Report •

February 4, 2009 at 01:33:22
Thanks Judago.
I used the quotes.

That is actually part of the code... you see I am trying to write an OXO (Tic Tac Toe) game - Single player, and need it to auto detect wheter USER inputted an 'x' or an 'o' the previous time!

It is proving quite difficult!!


Report •

Related Solutions

Ask Question