I trying to measure time using Windows command line.
echo %TIME% & timeout 5 > NUL & echo %TIME%
But this command prints two equal timestamps. Why? What I'am doing wrong?
timeout 5
is just for example.
I trying to measure time using Windows command line.
echo %TIME% & timeout 5 > NUL & echo %TIME%
But this command prints two equal timestamps. Why? What I'am doing wrong?
timeout 5
is just for example.
The interpreter first parses the whole line (replacing both %time%
with the same value (because same time of parsing)) before executing anything. You need delayed expansion to make it work.
If you need a command line solution:
cmd /v /c "echo !time! & timeout 5 & echo !time!"
This article https://blogs.msdn.microsoft.com/oldnewthing/20060823-00/?p=29993 says the ENV variables are expanded at the time the command is read. Your results would seem to indicate that the entire command line is read/parsed/expanded at once before anything is executed.