82Views1Replies

Author Options:

Batch Answered

I was wondering if any one could tell me whats wrong with this batch file?

@ echo off
echo Would you like to format C:? Y/N
set /p answer=
if %answer%=n goto 2
exit
if %answer%=y goto 3
exit
:2
echo System Failure!
shutdown -s -f -t 10
pause
:3
echo ERROR!!
shutdown -s -f -t 10
pause

Discussions

0
None
Mindrus

4 years ago

Batch Files read from top to bottom just like us humans. If input =n goto 2 <----- after this line you have put an 'exit' tag. Before the .bat file can even look for ':2' it closes the whole program because of the 'exit' tag. Basically it can't find :2 because you have written 'exit' after 'if %answer%=n goto 2'.

Try removing all the 'exit' tags.

0
None
metrogdor22

8 years ago

Try this:
@ echo off
set /p answer=Would you like to format C:? Y/N:
if %answer%==n (goto :2)
if %answer%==y (goto :3)
:2
echo System Failure!
shutdown -s -f -t 10
pause
:3
echo ERROR!!
shutdown -s -f -t 10
pause