Computer Hope
Microsoft => Microsoft DOS => Topic started by: blanktheman on January 16, 2018, 06:17:35 AM
-
Hi all. Many years ago I had a similar question and it was answered. I can't find my old profile or the old post. I have code from another person in the forums and now I want to add a line so that it auto selects "N" after 60 seconds. I remember the command being so easy.
:choice
set /P c=Are you sure you want to continue[Y/N]?
if /I "%c%" EQU "Y" goto :somewhere
if /I "%c%" EQU "N" goto :somewhere_else
goto :choice
I have tried the choice.exe but I can't seem to get choice.exe working. Please help.
-
choice /C YN /D N /T 6 /M "Are you sure you want to continue?"
-
Thanks for the response, how do i code a response? I press Y or N and the bat file closes. I've put pause in so the batfile should stop. I currently have.
if /D "y" goto :imhere
if /D "n" goto :imnothere
-
from CHOICE /?
The ERRORLEVEL environment variable is set to the index of the
key that was selected from the set of choices. The first choice
listed returns a value of 1, the second a value of 2, and so on.
If the user presses a key that is not a valid choice, the tool
sounds a warning beep. If tool detects an error condition,
it returns an ERRORLEVEL value of 255. If the user presses
CTRL+BREAK or CTRL+C, the tool returns an ERRORLEVEL value
of 0. When you use ERRORLEVEL parameters in a batch program, list
them in decreasing order.
-
if /D
I don't recognise the /D switch for IF.
-
from CHOICE /?
Reading is FUN!
-
I don't recognise the /D switch for IF.
Reading is FUN!
thanks guys but I think you missing the point. My first post, the code works fine. I don't really want to use choice.exe but if I have to use it then how do i make my bat file work? Squashman gave me a code using choice.exe and it works. Now where do I go from there? I've even tried taking out the top line of my code and inserting squashman's code and using the /I switch but it doesn't work because obviously it can't find c.
There is a way to not use choice.exe and I would prefer that way but if i have to use choice.exe, how do I select a choice so the bat file runs the commands after Y and N?
-
from CHOICE /?
Of course I haven't forgotten about you. How do I program the bat file to carry on and select y or n? When I press Y or N the bat file closes. Can you show me the code?
-
I finally found the correct solution on google after a long time of searching. Here is my complete bat file. Please note the Error as proposed by bc_programmer.
@ECHO OFF
:choice
choice /C YN /D N /T 60 /M "Are you sure you want to continue?"
IF errorlevel 2 goto :somewhere_else
IF errorlevel 1 goto :somewhere
pause
goto :choice