?

Log in

Previous Entry | Next Entry

cmd.exe Goodness

Here is part of the help for the "SETLOCAL" command in cmd.exe:
The SETLOCAL command will set the ERRORLEVEL value if given
an argument.  It will be zero if one of the two valid arguments
is given and one otherwise.  You can use this in batch scripts
to determine if the extensions are available, using the following
technique:

    VERIFY OTHER 2>nul
    SETLOCAL ENABLEEXTENSIONS
    IF ERRORLEVEL 1 echo Unable to enable extensions

This works because on old versions of CMD.EXE, SETLOCAL does NOT
set the ERRORLEVEL value. The VERIFY command with a bad argument
initializes the ERRORLEVEL value to a non-zero value.

Wow. Talk about a kludge. For one thing, there should not be a need for a "SETLOCAL" command in the first place. The environment should be local to a process already. This is how a Real operating system works. Second, this "technique" relies on an undocumented or unintentional feature of the "SETLOCAL" command in previous versions of cmd.exe.

This technique would be bad enough if it were a third party supplying it, but this is in Microsoft's own documentation!