Conditional symboles on Windows NT/XP command lines and the compatibility issues they cause

CONDITIONAL PROCESSING SYMBOLS

Conditional processing symbols allow you to control the execution of commands; allowing you to issue multiple commands from the same prompt and to govern program flow based on the results of a command. Using these in special ways allow you to extend the command prompt rules. These symbols may not be part of a file name. Note that filenames and extensions can be up to 256 characters long under Windows NT/2000/XP.

The conditional processing symbols are: " * : / \ ? < >

For a complete description of conditional symbols, use the system Help (Help and Support under Windows XP) using keyword: conditional. Extensions of the command processor, CMD.EXE over COMMAND.COM are described under Help and Support keyword: CMD. General commands are described under Help and Support keyword: commands. Under Windows XP after doing this, click the "Full text search matches" bar at the bottom of the results screen.

Conditional processing symbols

&
The ampersand (&) separates multiple commands on one command line.
( )
The parentheses groups multiple commands. See FOR
; ,
The semicolon or comma (; ,) separate command parameters.
^
The caret (^) allows you to use a command symbol as text (ignores the symbols special meaning).
&&
The double ampersand (&&) causes the command following this symbol to run only if command preceding symbol is successful. Under some circumstances (issue HELP CMD from NT DOS Prompt) this double Ampersand must be put in double-quotes.
||
The double pipe (||) causes the command following this symbol to run only if command preceding symbol fails. Also: IF ERRORLEVEL
%
The percent (%) sign is often used to designate batch file argument number; under Windows NT/2000/XP just use percent sign for this. To type a percent sign, use two percent signs; e.g., Echo 10%% would output 10%.

Examples

Therefore under Windows NT/2000/XP Command Prompt, the rules are slightly different than under Windows 9x or DOS. For example, one of these differences is that an Ampersand (&) is a special character under NT/2000/XP Command Prompt (or START/RUN) command lines. In particular, & is used to separate commands and so cannot simply appear as an option to a command.

For example, the command:
PKZIP -a -ex -& a:\Zipfile.zip c:\FilesToZip
works under all Windows 9x MS-DOS Prompt (or START/RUN) but would fail under Windows NT/2000/XP Command Prompt; in the latter case, preceed it with a caret (^). For example:
PKZIP -a -ex -^& a:\Zipfile.zip C:\FilesToZip
When writing Batch files this must be taken into consideration.

For example, to run the above DOS PKZIP command via a .BAT file that will run under Windows NT/2000/XP Command Prompt or any other Windows DOS (prompt), one could write the DOS Batch file:

@Echo off
REM Environment variable OS is set for Windows NT.
if NOT "%OS%" == "Windows_NT" GoTo NotNT
  Echo this is Windows NT
  PKZIP -a -ex -^& a:\ZipFile.ZIP C:\FilesToZip
  GoTo Next
:NotNT
  Echo this is NOT Windows NT
  PKZIP -a -ex -& a:\ZipFile.ZIP C:\FilesToZip