Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Limits on Windows environment variable nesting?

So, is there a limit to how deeply environment variables can be nested in Windows? I do a lot of development work and I'm trying to set up my development environment vars, and a lot of them nest off each other, ie.


GLEW=%THIRD_PARTY_ROOT%\GLEW
GLEW_1_5_5=%GLEW%\glew-1.5.5
GLEW_BIN_PATH=%GLEW_ROOT%\bin
GLEW_INCLUDE_PATH=%GLEW_ROOT%\include
GLEW_LIB_PATH=%GLEW_ROOT%\lib
GLEW_ROOT=%GLEW_1_5_5%

OSG=%THIRD_PARTY_ROOT%\OpenSceneGraph
OSG_2_8_3=%OSG%\OpenSceneGraph-2.8.3
OSG_BIN_PATH=%OSG_ROOT%\bin
OSG_INCLUDE_PATH=%OSG_ROOT%\include
OSG_LIB_PATH=%OSG_ROOT%\lib
OSG_ROOT=%OSG_2_8_3%

THIRD_PARTY_ROOT=C:\dev\third-party

But I was having a heck of a time getting them to actually expand properly. For a while when I looked at the output of set, I was just getting what looked like they were being expanded in order and so any ones that depended on foo_ROOT weren't being expanded properly. I tried enabling delayed expansion and that didn't help, but restarting seemed to... so maybe delayed expansion required a restart..

Either way, I have GLEW_BIN_PATH and OSG_BIN_PATH in my PATH variable and they refuse to expand. This is really frustrating because the dll's are residing there and of course I can get evvvverything else to expand... any thoughts?

Edit: I have them in the PATH variable as:

[everything else....];%GLEW_BIN_PATH%;%OSG_BIN_PATH%

So I'm not seeing an obvious cause to keep them from expanding out..

like image 706
trycatch Avatar asked Aug 29 '10 13:08

trycatch


People also ask

Is there a limit on the size of the environment variable?

Starting with Windows Vista and Windows Server 2008, there is no technical limitation on the size of the environment block. The GetEnvironmentVariable function determines whether a specified variable is defined in the environment of the calling process, and, if so, what its value is.

Is there a maximum number of characters per environment variable?

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.

Is there a limit on the size of the Environment Block?

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. – SimonS Apr 27 '16 at 6:08.

What is the length of an environment variable in CMD?

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.


1 Answers

I've had success with escaping the percent sign:

GLEW=%%THIRD_PARTY_ROOT%%\GLEW

THIRD_PARTY_ROOT=C:\dev\third-party

C:\>set GLEW
GLEW=C:\dev\third-party\GLEW

When viewing the variable from the Windows Environment Variable window, it will display as

GLEW | %THIRD_PARTY_ROOT%\GLEW

Note: The double percent signs will only work inside a script. If using on the command line, use the caret escape character (e.g. GLEW=^%THIRD_PARTY_ROOT^%\GLEW).

like image 71
justDev7a3 Avatar answered Oct 26 '22 17:10

justDev7a3