Page 1 of 1

Wait for Few Seconds before Executing a Command

Posted: 30 Jun 2012 22:47
by abc0502
I was building a menu for a usb and in this menu you choose an option, I was wondering how can i make the menu execute a command after a few seconds if it didn't take an option.

This is the code:
@echo off
cls
mode 70,25
color 09

:: This code is for the menu
:: second the code
:menu
SET "MSL=SET /P ".= "
SET "OSL=SET /P ".= "
SET "EL=end&echo."

echo.&echo.&echo.
%MSL%غححححححححححححححححححححححححححححححغ" <nul %EL%
%MSL%؛ ؛" <nul %EL%
%MSL%؛" <nul &call :C 0f " Main Menu" &echo ؛
%MSL%؛ ؛" <nul end&echo.
%MSL%غححححححححححححححححححححححححححححححغ" <nul %EL%&echo.&echo.
SET /P ".= " <nul &CALL :C 0e "Options" %EL%&echo.
%OSL%" <nul &CALL :C 07 " 1. Python" %EL%
%OSL%" <nul &CALL :C 07 " 2. Executor" %EL%
%OSL%" <nul &CALL :C 07 " 3. In-Deeb Notes" %EL%
%OSL%" <nul &CALL :C 07 " 4. Project Folder" %EL%&echo.&echo.

SET "Command="
SET /P "Command=Command > "
IF NOT DEFINED Command CLS&GOTO menu
IF %Command%==1 echo option 1 working
IF %Command%==2 echo option 2 working
IF %Command%==3 echo option 3 working
IF %Command%==4 echo option 4 working
CLS
GOTO menu

:: first the color code
:C
set /p " = " > "%~2" <nul
findstr /v /A:%1 /R "^$" "%~2" nul 2>nul
set /p ".=" <nul
if "%3" == "end" set /p ".= " <nul
del "%~2" >nul 2>nul
exit /b


Re: Wait for Few Seconds before Executing a Command

Posted: 30 Jun 2012 23:34
by foxidrive

Code: Select all

echo hangon...
ping -n 3 localhost >nul & echo oops!

Re: Wait for Few Seconds before Executing a Command

Posted: 30 Jun 2012 23:36
by Fawers
Well, you can do it with choice. But choice is not available on XP (unless you download it).

With choice.exe, you can set a default answer and a timeout; if the timer reaches 0, this default option will be chosen.
Download choice.exe from somewhere, put it in \windows\system32 (i put it there) and type choice /? on your command line. I'm pretty sure it'll solve your problem.

Re: Wait for Few Seconds before Executing a Command

Posted: 30 Jun 2012 23:54
by foxidrive
Ahh, I misread the question.

Choice is available in Vista and Windows 7 again I think.

Re: Wait for Few Seconds before Executing a Command

Posted: 01 Jul 2012 16:57
by Fawers
foxidrive wrote:Choice is available in Vista and Windows 7 again I think.

That's right. I don't even know why they took it off XP. :(