Microsoft KB Archive/65162

Using Batch File Variable Expansion May Hang System PSS ID Number: Q65162 Article last modified on 07-14-1993 PSS database name: O_MSDOS

3.x 4.x

MS-DOS

Summary:

When executing MS-DOS commands at the command prompt, the command line is limited to 128 characters. This limitation also extends to commands issued within a batch file. However, in a batch file, you can use the contents of previously defined environment variables in commands. This ability allows you to generate a command line longer than 128 characters. However, if you do this, the system may be left in an unstable state or may stop (hang), depending on the circumstances, because no length checking is performed.

Microsoft has confirmed this to be a problem with MS-DOS versions 3.2, 3.21, 3.3, and 4.01. This problem does not occur in later versions of MS-DOS.

More Information:

This problem can occur unexpectedly after a software installation if the PATH is approaching the 128-character limit. All MS-DOS environment variables are limited by the COMMAND.COM input buffer length of 128 characters. The PATH statement and other environment variables cannot exceed 127 characters, including spaces. The total length of the statement is 128 bytes, but the 128th byte is reserved for an “end of string” null byte. Software installation programs often add a line to the AUTOEXEC.BAT file to include the new program in the PATH. For example, before installing a new program, the PATH statment may appear as follows:

path c:;c:;c:;c:...(through 120 characters)

After installing a new program, the following statement is added to your AUTOEXEC.BAT file:

path c:;%path%

As part of processing this line, COMMAND.COM substitutes the current value of PATH for “%PATH%”. This pushes the length of this command over the 128-character limit, and because no length checking is performed, your system can hang.

Workarounds
If the second PATH statement is removed and the new program’s subdirectory is inserted in the initial PATH statement, this problem does not occur. The environment variable is truncated to 128 characters. Other workarounds are to shorten the names of your directories, or to remove a few directories.

For more information on workarounds for this problem, query on the following words:

PATH and LIMIT and 128

This problem displays the following symptoms:

MS-DOS Version Result ————– ——

3.3 System returns to the command prompt without echoing the TEST line. The next batch file that uses macro expansion hangs the system.

4.0 System hangs on execution of the TEST line.

4.01, 4.01a System spontaneously cold boots (causing memory tests) on execution of the TEST line.

Because of the nature of this problem, the above results may not be the same from system to system.

Additional reference words: 3.30 4.00 4.01 4.01a 4.x stop hang freeze noupd

Copyright Microsoft Corporation 1993.