Saturday, October 17, 2009

Unix: sleep <seconds> && command - equivalent in Windows

If your system has Windows Server resource tool kit, then the above construct should work fine as it has "sleep" command. If not, the following comes very close with a few hassles and gotchas.

Short Version: choice /T secs /D Y command
Long Version: choice /N /T secs /D Y >NUL command

    - Requires a number of key strokes.
    - You need to have or install choice.exe to be availabe in your path.
    - Notice that '||' is used instead of '&&'. Pipe-pipe is required if you wish to hit "Ctrl-C" to abort both choice and command together. If you used "&&" and hit "Ctrl-C", your command will still execute because choice returns a 0(zero - true) upon encountering "Ctrl-C".

No comments: