I sort of forgot to celebrate CLR Week last year, so let's say that CLR week is "on hiatus" until next year. To fill the summertime time slot, I'm going to burn off a busted pilot: This week is Batch File Week 2012. Remember, nobody actually enjoys batch programming. It's just something you have to put up with in order to get something done. Batch programming is the COBOL of Windows. (Who knows, if people actually like Batch File Week [fat chance], maybe it'll come back as a regular series.)

We'll open Batch File Week with a simple puzzle.

A customer reported that after running their batch file, almost no commands worked any more!

C:\> awesomebatchfile.bat
... awesome batch file does its work ...

C:\> reg query "HKLM\Software\Clients\Mail" /ve
'reg' is not recognized as an internal or external command,
operable program or batch file.

Wha? Maybe I can run regedit.

C:\> regedit
'regedit' is not recognized as an internal or external command,
operable program or batch file.

OMG OMG OMG OMG.

C:\> notepad
'notepad' is not recognized as an internal or external command,
operable program or batch file.

Okay, first, sit down and take a deep breath. Maybe take a Chill Pill.

My first question was "Does awesomebatchfile.bat modify the PATH variable?" (This was, strictly speaking, a psychic debugging question, but a rather obvious one.)

The customer replied, "Nope. Here, I'll send you the whole thing."

And there it was, right there at the top of awesomebatchfile.bat:

set path=C:\awesomedir
if NOT "%1"=="" set path=%1
cd /d %path%
echo Awesomeness commencing in the %path% directory!
...

The customer figured it would be convenient to have a variable called path, unaware that this variable has special meaning to the command interpreter. The customer didn't make the connection that their seemingly private variable called path was connected to the system variable of the same name (but by convention capitalized as PATH).