case study of phases 4/5

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Liviu
Expert
Posts: 470
Joined: 13 Jan 2012 21:24

case study of phases 4/5

#1 Post by Liviu » 05 Feb 2013 12:48

The "phases" refer to jeb's http://stackoverflow.com/questions/4094699/how-does-the-windows-command-interpreter-cmd-exe-parse-scripts. The code should speak for itself ;-) Basically, it shows the difference between batch vs. cmd parsing, and also why file/dir for loops are better run with delayed expansion disabled.

Code: Select all

C:\tmp\exc>dir /b *.tmp
exc!!2!!.tmp
[!!date!!].tmp
[%time%].tmp

C:\tmp\exc>type test-exc.cmd
@echo. & setlocal disabledelayedexpansion & for %%f in (*.tmp) do @echo %%f
@echo. & setlocal enabledelayedexpansion  & for %%f in (*.tmp) do @echo %%f

C:\tmp\exc>test-exc

exc!!2!!.tmp
[!!date!!].tmp
[%time%].tmp

exc.tmp
[Tue 02/05/2013].tmp
[%time%].tmp

C:\tmp\exc>cmd /v:on /c for %f in (*.tmp) do @echo %f
exc!!2!!.tmp
[!Tue 02/05/2013!].tmp
[%time%].tmp

C:\tmp\exc>cmd /v:off /c for %f in (*.tmp) do @echo %f
exc!!2!!.tmp
[!!date!!].tmp
[%time%].tmp

Liviu

P.S. Amazing sometimes how long it may take to remember things one thought they knew ;-)

Post Reply