Fun with Windows Timeout command…

(this is a guest post by Tenox)

I’m pretty good at finding bugs in Windows and I get a new one every couple of weeks or so. Today I found out this unbelievable gem:

So there is this (cmd.exe) command called timeout. It works roughly similar to sleep(1) under Unix. It is supposed to stop execution of a batch script for a given period of time. Example:

In reality just wishful thinking, because apparently this is not always the case. Sometimes it does and sometimes… it doesn’t.

Wait… what?

Sounds unbelievable but it appears the timeout command uses Real Time Clock for it’s sleep function. If you change the clock while timeout is running…

t2LOL 🙂

I found this because my batch scripts were stuck for rather long time when a machine would have time changed by NTP. If the change was negative the timeout command would wait x thousand seconds. When the change was positive the integer rolled and timeout stopped immediately causing avalanche of problems.

So beware to timeout eating your batch scripts…

9 thoughts on “Fun with Windows Timeout command…

  1. I’m always reminded of Microsoft’s POSIX subsystem which could barely run tar & vi.. Sure windows can ‘script’ but it isn’t meant to do so.

    Such a shame that they bought out Interix, and killed their product line. I guess if the Kernel Personality API were open, someone would port Linux or BSD, then nobody would run NT server stuff.

  2. Windows 8.1/2012 theoretically has Cygwin/Mingw. But I’m not moving till they restore start menu.

    As for OpenNT – yes it’s the same thing as Interix. I would like to get v2.1 for NT4.0!

  3. Alternatives to timeout, if anybody cares (time set to 5 seconds):

    choice /T 5 /D n > NUL

    ping 192.168.x.y -w 5000 -n 1 > NUL

    (192.168.x.y has to be unreachable address)

Leave a Reply to tenox Cancel reply

Your email address will not be published. Required fields are marked *

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