I am new to batch files, so please forgive me if I don't use the proper terminology here.
I have a batch file that needs to undeploy one specific application from all my listed Glassfish domains. Here is the code:
@echo off
setlocal EnableDelayedExpansion
set glassfishDomains=domainA4841,domainB4842
for /d %%a in (%glassfishDomains%) do (
set fullDomain=%%a
set port=!fullDomain:~-4!
set domain=!fullDomain:~0,-4!
echo Undeploying appName on domain !domain! !port!
asadmin --host localhost --port !port! undeploy appName
echo.
)
The problem is that it is "losing the state" after the asadmin commands is executed for the first time.
asadmin --host localhost --port !port! undeploy app
Just for clarity, asadmin.bat is Glassfish's command line tool.
If I remove this line/command from the file, the loop performs the string extraction just fine, using delayed expansion. This is the resulting output in that case:
Undeploying app on domain domainA 4841
Undeploying app on domain domainB 4842
By "losing state" I mean that variables don't get the correct values anymore. After the first asadmin command execution, I start to get this result:
Undeploying appName on domain domainA 4841
Command undeploy executed successfully.
D:\>(
set fullDomain=domainB4842
set port=!fullDomain:~-4!
set domain=!fullDomain:~0,-4!
echo Undeploying appName on domain !domain! !port!
asadmin --host localhost --port !port! undeploy appName
echo.
)
domainB4842
Undeploying appName on domain !domain! !port!
CLI136: Port !port! should be a numeric value.
Command --host failed.
So the question is if there is a way to avoid "losing the script state" after these commands execute? Or is this some sort of limitation from that tool (asadmin)?