Quais são as razões técnicas para o limite de 1024 caracteres
O limite ao qual você se refere não é de 1024 bytes. Como explicado no artigo que você vinculou a isso foi um bug, com um hotfix disponível.
O artigo diz explicitamente que o limite é 2048 bytes para a função CreateEnvironmentBlock
.
Além disso, o bug era específico para duas versões antigas do Windows (XP e Server 2003).
When an application calls the CreateEnvironmentBlock function to retrieve the environment variables on a Microsoft Windows Server 2003-based or Microsoft Windows XP-based computer, the returned path environment variable is truncated to 1,024 bytes. This behavior occurs even though the maximum size of an environment variable is 2,048 bytes. This problem prevents the application from obtaining the correct environment variable.
Então o limite é 2048 caracteres?
O limite real é de 32.760 caracteres. No entanto, é improvável que você atinja esse máximo teórico na prática.
-
Um arquivo em lote é restrito pelo comprimento máximo da linha de comando, pois a variável de ambiente precisa se ajustar ao buffer da linha de comando do processador em lote.
Em computadores que executam o Microsoft Windows XP ou posterior, o comprimento máximo da cadeia que você pode usar no prompt de comando é de 8191 caracteres.
O Prompt de Comando ignora as variáveis de ambiente que são herdadas do processo pai e são mais longas do que suas próprias limitações de 8191 caracteres.
-
A definição da chave do Registro Environment tem um limite de 2048 caracteres no código que analisa essa chave do Registro e cria um bloco de ambiente fora do isto.
Fontes documentadas abaixo.
Como esse valor ( PATH
) fica corrompido pelo uso normal?
Como explicado mais adiante, isso pode ocorrer se o sistema PATH
for modificado para ter mais de 1920 caracteres.
Você não forneceu informações suficientes em sua pergunta para um diagnóstico exato sobre o motivo pelo qual isso está acontecendo.
Eu tenho um grande usuário PATH
variable set
Existe um limite específico na variável de ambiente PATH
.
Para que a variável do usuário PATH
seja mesclada com êxito com a variável PATH
do sistema, a variável PATH
do sistema deve ser < 1920 caracteres.
Found out that on Windows Server 2003, once the system PATH passes 1920 characters, the user
PATH
environment variable is no longer merged with it to set the processPATH
environment variable, even though the full systemPATH
(even if larger) will be included in the processPATH
variable.
Source O echo% PATH% expande somente para o sistema ou também as variáveis do usuário? responda por David Heffernan
Quais são os limites em um caminho de arquivo?
Maximum Path Length Limitation
In the Windows API (with some exceptions discussed in the following paragraphs), the maximum length for a path is MAX_PATH, which is defined as 260 characters.
A local path is structured in the following order: drive letter, colon, backslash, name components separated by backslashes, and a terminating null character.
For example, the maximum path on drive D is
D:\some 256-character path string<NUL>
where<NUL>
represents the invisible terminating null character for the current system codepage. (The characters<
and>
are used here for visual clarity and cannot be part of a valid path string.)Note: File I/O functions in the Windows API convert "/" to "\" as part of converting the name to an NT-style name, except when using the "\?\" prefix as detailed in the following sections.
The Windows API has many functions that also have Unicode versions to permit an extended-length path for a maximum total path length of 32,767 characters.
- This type of path is composed of components separated by backslashes, each up to the value returned in the
lpMaximumComponentLength
parameter of theGetVolumeInformation
function (this value is commonly 255 characters). To specify an extended-length path, use the "\?\" prefix. For example, "\?\D:\very long path".Note: The maximum path of 32,767 characters is approximate, because the "\?\" prefix may be expanded to a longer string by the system at run time, and this expansion applies to the total length.
Fonte Nomeando arquivos, caminhos e Namespaces
Qual é o comprimento máximo de uma variável de ambiente?
The theoretical maximum length of an environment variable is around 32,760 characters. However, you are unlikely to attain that theoretical maximum in practice.
All environment variables must live together in a single environment block, which itself has a limit of 32767 characters.
But that count is the sum over all environment variable names and values, so you could, I guess, hit that theoretical maximum length if you deleted all the environment variables and then set a single variable called X with that really huge 32,760-character value.
In practice, of course, you have to share the environment block with all the other variables in the block, so your random call to
SetEnvironmentVariable
with a 32,760-character string is unlikely to succeed.But that’s not your only practical limit.
It also depends on how you’re setting the variable; i.e., the code that your environment-variable-setting technique passes through before it gets to the
SetEnvironmentVariable
call.If you’re using a batch file, then you’re constrained by the maximum command line length since the environment variable needs to fit into the command line buffer of the batch processor.
On the other hand, maybe you’re setting the Environment registry key, in which case you run into a 2048-character limit in the code that parses that registry key and builds an environment block out of it.
There’s also a limitation in the dialog box for interactively setting environment variables, the numeric value of which I don’t happen to know off the top of my head.
Fonte Qual é o comprimento máximo de uma variável de ambiente? por Raymond Chen (funcionário da Microsoft).
Prompt de comando ( Cmd.exe
) limitação de cadeia de linha de comando
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 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 expand EnvironmentVariable2 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 parameter1 parameter2
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). See SetEnvironmentVariable function.
Fonte Limitação da cadeia de comandos da linha de comandos (Cmd.exe)