今天在跑一个批处理文件的时候,出现了下面的错误:The input line is too long
。
搜索发现,是跟
path
有关,碰巧我这几天装的软件比较多,觉得可能是path
太长了,然后就试着在环境变量下的path
删掉了几个条目,结果又弹出了下面的对话框。说我的环境变量太长了,超过了2047个字符。This environment variable is too large. This dialog allows setting values up to 2047 characters long.
image.png
我想了一下,觉得可能是删的不够多,就每删一个就试着保存一下,终于在删除了7、8个之后,不在弹出这个对话框了。然后上边的脚本也可以正常的运行了。
表面看起来像是因为环境变量的长度超过了2047才导致的问题,但是我隐隐的觉得好像并没有这么简单。
查阅windows文档:
The maximum size of a user-defined environment variable is 32,767 characters. There is no technical limitation on the size of the environment block. However, there are practical limits depending on the mechanism used to access the block. For example, a batch file cannot set a variable that is longer than the maximum command line length.
然而,有另外一篇文章好像更能解释这个问题:
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.
但是,我用的系统是win 10,理论上限制应该是8191,而不是2047。
最终,我找到了这样一个解释,详情:
Setting directly in the registry at
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
fails since regedit truncates entered strings after 2047 characters.
但是,并没有官方文档来支持这一论断😳。
感觉在找下来意义也不大了,先停在这吧。
网友评论