Log in

No account? Create an account

Wed, May. 26th, 2010, 03:24 pm
Another Reason I Love PowerShell and Python...

I've been refactoring a ton of scripts lately and today I was doing a simple rename of an environment variable that we'll call "ABC" to "DEFG".  Well in some random batch file there was a snippet similar to:
IF "%ABC%" == "" ( 
    REM Do something

REM ...
REM a bunch more cruft
REM ...


    REM Do something else

Astute observers will notice the "Do something else" piece is incorrect as the left parenthesis needs to be on the same line as the IF statement for this to work.  For some reason I cannot fathom though, Windows allowed this mistake to run correctly.  Well as soon as I did a global search/replace on "ABC" to "DEFG", lo and behold Windows decided this was in fact a grammar mistake.  Spent an hour or so digging through "a bunch more cruft" (quite more significant than the three lines I've abstracted it to be) to figure out what the underlying issue was.

Writing new scripts for MS Windows?  Please do yourself a favor and use PowerShell, IronPython, or even Perl to save yourself and maintainers of your code future troubles:)