The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,226 other followers

Batch file examples – Wait using CHOICE (via: RobVanDerWoude.com)

Posted by jpluimers on 2012/01/19

Most batchfile wait examples require a functioning network connection.

Just in case you haven’t, Rob van der Woude has a nice example on his batch file Wait page using the Choice command.

The bummer is: choice is available on almost all Windows versions (actually since DOS 6.x), but not on Windows XP, and not on Windows 2000, but it is there in Windows Vista and up where you can use the timeout command :(

Alternatives can be found in the other examples on Rob’s wait page.

CHOICE – Wait.bat: Uses CHOICE to wait for a specified number of seconds.

By using REM | before the CHOICE command, the standard input to CHOICE is blocked, so the only “way out” for CHOICE is the time-out specified by the /T parameter.

The idea was borrowed from Laurence Soucy, I added the /C parameter to make it language independent.

@ECHO OFF
IF "%1"=="" GOTO Syntax
ECHO.
ECHO Waiting %1 seconds
ECHO.
REM | CHOICE /C:AB /T:A,%1 > NUL
IF ERRORLEVEL 255 ECHO Invalid parameter
IF ERRORLEVEL 255 GOTO Syntax
GOTO End
:Syntax
ECHO.
ECHO WAIT for a specified number of seconds
ECHO.
ECHO Usage: WAIT n
ECHO.
ECHO Where: n = the number of seconds to wait (1 to 99)
ECHO.
:End

–jeroen

via: Batch file examples – Wait.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

 
%d bloggers like this: