Microsoft KB Archive/830473

= Command prompt (Cmd. exe) command-line string limitation =

Article ID: 830473

Article Last Modified on 2/1/2007

-

APPLIES TO


 * Microsoft Windows Server 2003, Datacenter Edition (32-bit x86)
 * Microsoft Windows Server 2003, Enterprise Edition (32-bit x86)
 * Microsoft Windows Server 2003, Standard Edition (32-bit x86)
 * Microsoft Windows Server 2003, Web Edition
 * Microsoft Windows XP Home Edition
 * Microsoft Windows XP Professional
 * Microsoft Windows 2000 Advanced Server
 * Microsoft Windows 2000 Professional Edition
 * Microsoft Windows 2000 Server
 * Microsoft Windows NT Server 4.0 Standard Edition
 * Microsoft Windows NT Workstation 4.0 Developer Edition

-





SUMMARY
This article discusses the limitation to the length of the strings that you use from the command prompt in Command Prompt (Cmd.exe) and the methods that you can use to work around this limitation.



MORE INFORMATION
On computers running Microsoft Windows XP or later, the maximum length of the string that you can use at the command prompt is 8191 characters. On computers running Microsoft Windows 2000 or Windows NT 4.0, the maximum length of the string that you can use at the command prompt is 2047 characters.

This limitation applies to the command line, individual environment variables (such as the PATH variable) that are inherited by other processes, and all environment variable expansions. If you use Command Prompt to run batch files, this limitation also applies to batch file processing.

Examples
The following list gives you some examples of how this limitation applies to commands that you run in Command Prompt and commands that you use in a batch file.  In Command Prompt, the total length of the following command line that you use at the command prompt cannot contain more than either 2047 or 8191 characters (as appropriate to your operating system):

'''cmd.exe /k .exe ,   ... '''

 In a batch file, the total length of the following command line that you use in the batch file cannot contain more than either 2047 or 8191 characters (as appropriate to your operating system):

'''cmd.exe /k .exe ,   ... '''

This limitation applies to command lines that are contained in batch files when you use Command Prompt to run the batch file. In Command Prompt, the total length of  after you expand   and   cannot contain more than either 2047 or 8191 characters (as appropriate to your operating system): 

c:> set =

 In a batch file, the total length of the following command line after you expand the environment variables in the command line cannot contain more than either 2047 or 8191 characters (as appropriate to your operating system):

 .exe  

 Even though the Win32 limitation for environment variables is 32,767 characters, Command Prompt ignores any environment variables that are inherited from the parent process and are longer than its own limitations of either 2047 or 8191 characters (as appropriate to the operating system). For more information about the SetEnvironmentVariable function, visit the following Microsoft Web site:

http://msdn2.microsoft.com/en-us/library/ms686206.aspx



How to work around the limitation
To work around the limitation, use one or more of the following methods (as appropriate to your situation):  Modify programs that require long command lines so that they use a file that contains the parameter information, and then include the name of the file in the command line.

For example, instead of using the  .exe  ...  command line in a batch file, modify the program to use a command line that is similar to the following command line, where   is a file that contains the required parameters (  ... ):

.exe c:\temp\ .txt

</li> Modify programs that use large environment variables so that the environment variables contain less than either 2047 or 8191 characters (as appropriate to your operating system).

For example, if the PATH environment variable contains more than either 2047 or 8191 characters (as appropriate to your operating system), use one or more of the following methods to reduce the number of characters:  Use shorter names for folders and files.</li> Reduce the depth of folder trees.</li> Store files in fewer folders so that fewer folders are required in the PATH environment variable.</li> Investigate possible methods that you can use to reduce the dependency of PATH for locating .dll files.</li></ul> </li></ul>

Additional query words: cmd cmd.exe &quot;command prompt&quot; 2048 2047 2046 8192 8191 environment variable PATH command line

Keywords: kbinfo KB830473

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.