Windows CMD "Error 87" caused by "process_begin: CreateProcess(...."

来源:互联网 发布:淘宝售后服务管理 编辑:程序博客网 时间:2024/04/28 07:31

基础知识思考整理
http://blog.csdn.net/aganlengzi/article/details/54580983

现象:

报错时候的样子基本是这样的,一大堆字符串打印出来,其中最后一般是:

process_begin: CreateProcess(很长的字符串xxxx Error 87

细节可以忽略,类似这样(网上找的)。
cmderror87

原因:

一般不是当前正在用的编译器等软件的原因(当然也有这种可能)。
多数情况下是Windows cmd.exe的锅:
因为自xp以后,windows的cmd窗口或者batch处理文件一条命令容纳的最大字符数是8191,其中包括命令和参数.而当执行一个命令其参数过长时就有可能超过这个限制,便会报错,这是操作系统的报错。

解决办法:

最可行的是缩短文件路径、文件名等,微软的支持页面也给出了解决方法。为了大家阅读方面,索性都贴在下方了:

以下引自[1]

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.ExamplesThe 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 ExecutableFile.exe parameter1, parameter2 … parameterN

  • 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 ExecutableFile.exe parameter1, parameter2 … parameterN

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 EnvironmentVariable1 after you expandEnvironmentVariable2 and EnvironmentVariable3 cannot contain more than either 2047 or 8191 characters (as appropriate to your operating system):
    c:> set EnvironmentVariable1=EnvironmentVariable2EnvironmentVariable3

  • 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):
    ExecutableFile.exe parameter1parameter2

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 ExecutableFile.exe Parameter1 Parameter2 …ParameterNcommand line in a batch file, modify the program to use a command line that is similar to the following command line, where ParameterFile is a file that contains the required parameters (parameter1 parameter2 …ParameterN):
    ExecutableFile.exe c:\temp\ParameterFile.txt

  • 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.
    * Reduce the depth of folder trees.
    * Store files in fewer folders so that fewer folders are required in the PATH environment variable.
    * Investigate possible methods that you can use to reduce the dependency of PATH for locating .dll files.

参考:

[1] https://support.microsoft.com/en-us/kb/830473

0 0
原创粉丝点击