I noticed that ENABLEDELAYEDEXPANSION is set so my .bat files have delayed expansion enabled. This causes some problems with exclamation marks (!).
What would be the best way to avoid these problems?
Setlocal help says:
Code: Select all
These modifications last until the matching ENDLOCAL command regardless of their setting prior to the SETLOCAL command.
- I could use ENDLOCAL before I call my .bat and then use SETLOCAL ENABLEDELAYEDEXPANSION when I get back to automenu.bat.
- I could use SETLOCAL DISABLEDELAYEDEXPANSION before I call my .bat and use SETLOCAL ENABLEDELAYEDEXPANSION when I return from my .bat.
1.cmd:
Code: Select all
@echo off
setlocal ENABLEDELAYEDEXPANSION
set test_par=Y!Y
echo 1_cmd:%test_par%
echo 1_cmd:!test_par!
echo.
echo calling 2.cmd
call 2.cmd
echo return from 2.cmd
echo.
echo 1_cmd:%test_par%
echo 1_cmd:!test_par!
Code: Select all
@echo off
set test_par2=X!X
echo 2_cmd:%test_par2%
echo 2_cmd:!test_par2!
echo.
Code: Select all
1_cmd:YY
1_cmd:YY
calling 2.cmd
2_cmd:XX
2_cmd:XX
return from 2.cmd
1_cmd:YY
1_cmd:YY
Thanks.
Saso