Wait for Few Seconds before Executing a Command

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Wait for Few Seconds before Executing a Command

#1 Post by abc0502 » 30 Jun 2012 22:47

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


foxidrive
Expert
Posts: 6033
Joined: 10 Feb 2012 02:20

Re: Wait for Few Seconds before Executing a Command

#2 Post by foxidrive » 30 Jun 2012 23:34

Code: Select all

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

Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: Wait for Few Seconds before Executing a Command

#3 Post by Fawers » 30 Jun 2012 23:36

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.

foxidrive
Expert
Posts: 6033
Joined: 10 Feb 2012 02:20

Re: Wait for Few Seconds before Executing a Command

#4 Post by foxidrive » 30 Jun 2012 23:54

Ahh, I misread the question.

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

Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: Wait for Few Seconds before Executing a Command

#5 Post by Fawers » 01 Jul 2012 16:57

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. :(

Post Reply