'Why does the command "Timeout" in a batch file suddenly not work anymore?

Did I miss a change of the Windows internal "timeout" command?

I have a batch file for a long time now that shows me the version number of a program. I added the timeout command to keep the CMD window opened for a few seconds. So my batch file now looks like this:

context -version
timeout 7

This worked fine but since some Windows update (obviously), the CMD windows closes directly as if the timeout command doesn't work anymore. When I start the file from a CMD window I get a message:

D:\CTX>timeout 7
Try 'timeout --help' for more information.

The file is as it was since I created it, but the behavior is new to me.

So can anybody tell me what I is going wrong here?



Solution 1:[1]

I believe you've probably acquired a different version of timeout since the help prompt --help is a \*nixy style option-specifier.

Try, from the prompt

where /T timeout.*

which should list the timeout versions on the path and may assist in locating the rogue version.

Solution 2:[2]

TIMEOUT is not an internal command of cmd.exe (Windows Command Processor) like FOR or DIR.

It is an external command which means a console application being located in the Windows system directory %SystemRoot%\System32.

On using just timeout without file extension and without full path, the Windows command interpreter searches first in the current directory with timeout.* for a file having a file extension listed in the local environment variable PATHEXT.

If no such file can be found in current directory, the Windows command interpreter continues the search for timeout.* with a file extension listed in PATHEXT in the directories defined in the local environment variable PATH.

The system PATH is defined as follows on Windows Vista and later versions of Windows:

%SystemRoot%\system32;%SystemRoot%\system32;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;

For that reason it is usually found first %SystemRoot%\System32\timeout.exe on using just timeout in a batch file.

But if the current directory contains a file with name timeout.* having a file extension listed also in environment variable PATHEXT, or PATH was redefined locally or system wide by an installer which put other directory paths at the beginning instead of appending them at the end, and one of these directories contains also a timeout.* file, the Windows command interpreter runs this executable or script.

The suggestions for solving this problem:

  1. Use in the batch file %SystemRoot%\System32\timeout.exe because then the Windows command processor must not search for this executable and it can't happen that the wrong timeout is executed mistakenly, except the environment variable SystemRoot is modified locally which is very unlikely in comparison to PATH manipulations.

  2. Open Windows Control Panel - System and Security (on View by: Category selected) - System - Advanced system settings (blue link on left side), select tab Advanced and click on button Environment Variables... There can be also clicked on Windows Start button and entered on keyboard environment and Windows suggests in the menu Edit environment variables for your account and Edit the system environment variables in the language of Windows. Click the latter suggested item and if necessary depending on Windows version next on button Environment Variables... Then search in lower half in list of System variables for Path, select this environment variable, click on Edit, and move all directory paths left or above (depends on Windows version) of %SystemRoot%\system32 to the end of the directories list.

  3. Please report to the author of the application or software bundle which modified system PATH and inserted their directory paths at beginning instead of appending them at end about this wrong modification of Windows system PATH.

As Magoo wrote already: a timeout.* ported from Unix to Windows is obviously executed on your Windows machine because of the output help statement. To get help on a command on Windows, the command has to be executed usually with parameter /? and not with -h or --help as on Unix.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 shA.t
Solution 2