I have issue with printing of environment variable %time% inside of FOR loop. I'm no sure if it is related to setlocal enabledelayedexpansion but it seems to be.
I am trying to figure this out in CMD.exe not in .bat script.
Without setlocal enabledelayedexpansion it looks like:
C:\Users\dabaran\Desktop\cs50\src\C>for /L %i in (1,1,3) do echo [%time%]
C:\Users\dabaran\Desktop\cs50\src\C>echo [21:47:27,19]
[21:47:27,19]
C:\Users\dabaran\Desktop\cs50\src\C>echo [21:47:27,19]
[21:47:27,19]
C:\Users\dabaran\Desktop\cs50\src\C>echo [21:47:27,19]
[21:47:27,19]
C:\Users\dabaran\Desktop\cs50\src\C>
If I try to use setlocal enabledelayedexpansion it looks like below:
C:\Users\dabaran\Desktop\cs50\src\C>Setlocal EnableDelayedExpansion
C:\Users\dabaran\Desktop\cs50\src\C>for /L %i in (1,1,3) do echo !time!
C:\Users\dabaran\Desktop\cs50\src\C>echo !time!
!time!
C:\Users\dabaran\Desktop\cs50\src\C>echo !time!
!time!
C:\Users\dabaran\Desktop\cs50\src\C>echo !time!
!time!
C:\Users\dabaran\Desktop\cs50\src\C>
I've tried to use timeout as well in order to create some delayed between different iterations of for loop but time is still not updated.
Don't understand why time variable is not being expanded !time! but instead stored as string.
Thank you.
Best Regards, Damian Baran