总长度为8191个字符,也许是这样的。或者这取决于您正在运行的程序。
来源:试错(Windows 8.1 / PSv4):
Start-Process -FilePath cmd -ArgumentList (@('/k','echo 1') + (2..1852))
Start-Process -FilePath cmd -ArgumentList (@('/k','echo 1') + (2..1853))
在大约6769处触发异常:
PS C:\> Start-Process -FilePath cmd -ArgumentList (@('/k','echo 1') + (2..6768))
Start-Process : This command cannot be run due to the error: The filename or extension is too long.
At line:1 char:1
+ Start-Process -FilePath cmd -ArgumentList (@('/k','echo 1') + (2..676 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand
但是,如果我稍微调整一下数字(2..1852|%{$_*100})
,那么它就会更早失败。这表明重要的不是参数数量,而是组合结果的字符串长度。
((@('/k','echo 1') + (2..1852)) -join " ").Length
请在谷歌上搜索8165 limit cmd
并获得以下结果:
命令行字符串的最大长度
https://support.microsoft.com/en-gb/kb/830473
在运行 Microsoft Windows XP 或更高版本的计算机上,您可以在命令提示符中使用的字符串的最大长度为8191个字符。因此,要么是8191个字符,要么...也许这取决于您调用的程序。300 * 32 将会超过这个限制。但是,如果您已经有一个可以处理它的程序 - start-process 似乎没有问题将1,800个项目的数组作为参数列表。
Start-Process
将参数组合成一个带有空格和引号格式的字符串,因此 200-300 * (32 + 1) 大约会有 6000-9000 个字符。这将是任何 Windows 命令行可能具有的最大长度,但我迄今为止还没有找到任何资源,所以我认为这可能值得在 Stack 上提问。 - Adwaenyth