Is there any solution for it?




Can we save more chars in one variable in CMD? Is it possible?
Moderator: DosItHelp
at this site Microsoft documentation wrote: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.
Code: Select all
@echo off &setlocal EnableDelayedExpansion
set /a "zeros=0, ones=1"
for /l %%i in (1 1 12) do set "zeros=!zeros!!zeros!"
for /l %%i in (1 1 12) do set "ones=!ones!!ones!"
set a=!zeros!!ones:~-4093!
echo(!a!
pause
aGerman wrote:The maximum string length in batch is 8191 characters.
Code: Select all
@echo off &setlocal EnableDelayedExpansion
set /a "zeros=0, ones=1"
for /l %%i in (1 1 12) do set "zeros=!zeros!!zeros!"
for /l %%i in (1 1 12) do set "ones=!ones!!ones!"
set aaa=!zeros!!ones:~-4081!
echo(!aaa!
Call Getlen "%aaa%"
Title %errorlevel%
pause
Kvc wrote:The valid length of the String saved in a variable is 8177 characters.
Kvc wrote:I didn't understood the 32 KBs block concept.
The issue in that case is not the variable length itself; the limiting bottleneck in your case is this line:Kvc wrote:And, i changed your code little... for verification purposes. (see numbers & Getlen function call)Code: Select all
@echo off &setlocal EnableDelayedExpansion
set /a "zeros=0, ones=1"
for /l %%i in (1 1 12) do set "zeros=!zeros!!zeros!"
for /l %%i in (1 1 12) do set "ones=!ones!!ones!"
set aaa=!zeros!!ones:~-4081!
echo(!aaa!
Call Getlen "%aaa%"
Title %errorlevel%
pause
And, even on increasing the var_name's length - the max. chars saved in a var stringare still of 8177 chars. (try changing the '4081' to '4082' - you'll get max. len error) But, with the above 4081.. you won't.
Code: Select all
Call Getlen "%aaa%"
Code: Select all
@echo off &setlocal EnableDelayedExpansion
set /a "zeros=0, ones=1"
for /l %%i in (1 1 12) do set "zeros=!zeros!!zeros!"
for /l %%i in (1 1 12) do set "ones=!ones!!ones!"
set _=!zeros!!ones:~-4093!
echo(!_:~8188!
cmd /d /a /v:on /c">"getLength.txt" set _"
for %%a in ("getLength.txt") do set /a "_.length=%%~za"
set _.length
goto :eof