(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…
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…
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.
OpenNT was supposed to do that http://windowsitpro.com/systems-management/opennt
Make sure to check out this screenshot: http://windowsitpro.com/site-files/windowsitpro.com/files/archive/windowsitpro.com/content/content/3122/screen_01.gif
too bad, it could have been useful. Instead windows 8.1/server 2012 has nothing..
Isn’t OpenNT what later became Interix?
Yep!
Indeed. This is an interesting read on the subject. http://brianreiter.org/2010/08/24/the-sad-history-of-the-microsoft-posix-subsystem/
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!
it’s not a subsystem as much it is a library
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)