I have an automation routine setup that performs a bunch of tasks. In all of my scripts, I first call an "environment" file to set a handful of variables for the given operation. In looking over my "environment" file, there is an opportunity to use an array to populate some variables to ensure it stays dynamic when porting over to another environment instead of having to edit each time.
The challenge is when setting up an array I need to use the command:
SETLOCAL ENABLEDELAYEDEXPANSION in the script but then when I call this "environment" script from my other scripts, obviously all variables set inside it are rendering nothing since they were local.
How do I get around this?
Here is the array in my "environment" script:
Code: Select all
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
FOR %%A IN (
"HYPER-UTIL-PRD|PROD|net.tcp://HYPER-UTIL-aaa:5210/Oracle/Drm/ProcessManager|server1.client.com|server001.onetakeda.com"
"HYPER-UTIL-TST|TEST|net.tcp://HYPER-UTIL-bbb:5210/Oracle/Drm/ProcessManager|server1.client.com|serverp002.onetakeda.com"
"HYPER-UTIL-DEV|DEV|net.tcp://HYPER-UTIL-ccc:5210/Oracle/Drm/ProcessManager|server1.client.com|server003.onetakeda.com"
) DO (
FOR /F "tokens=1-5 delims=|" %%a IN (%%A) DO (
SET "STR[%%a].HOST=%%a"
SET "STR[%%a].ENV=%%b"
SET "STR[%%a].DRM_URL=%%c"
SET "STR[%%a].TM1_SERVER=%%d"
SET "STR[%%a].TEMPO_SERVER=%%e"
)
)
ECHO Host = !STR[%COMPUTERNAME%].HOST!
ECHO Env = !STR[%COMPUTERNAME%].ENV!
ECHO DRM URL = !STR[%COMPUTERNAME%].DRM_URL!
ECHO TM1 Server = !STR[%COMPUTERNAME%].TM1_SERVER!
ECHO Tempo Server = !STR[%COMPUTERNAME%].TEMPO_SERVER!
POWERSHELL -nop -c "& {sleep 5}"
::-- Set Environment --::
SET "_ENV=!STR[%COMPUTERNAME%].ENV!"
::--:::::::::::::::::::::::::::::::::--::
::-- SET PATH VARIABLES --::
::--:::::::::::::::::::::::::::::::::--::
FOR %%A IN ("%~dp0..\..\..\..\Utilities") DO SET "UTILPATH=%%~fA\"
FOR %%A IN ("%~dp0..\..") DO SET "MAINPATH=%%~fA\"
SET "ARCHIVEPATH=%MAINPATH%Archives\"
SET "ERRORPATH=%MAINPATH%Errors\"
SET "FILEPATH=%MAINPATH%Files\"
Code: Select all
::-- Set Working Directory as Script Path --::
CD /D "%~dp0"
::-- Call Environment File --::
CALL "_env.cmd"