@rem Suppresses the display of each command on the screen as it is executed @echo off @rem Clear screen @cls @rem Print a message @echo This is a message @rem Block until the user press a key pause
@echo Argument one is: %1 @echo Argument two is: %2 ... rem Conrol if .%1.==.. goto usage ... :usage ...
@set variable=World @echo Hello %variable% rem Add a path to the environmental variable PATH PATH %PATH%;mypath
| Variable | Description |
|---|---|
| %CD% | Expands to the current directory. |
| %DATE% | Expands to the same output as typing DATE. |
| %TIME% | Expands to the same output as typing TIME. |
| %RANDOM% | Generates a random integer in the range of 0 - 32767. |
| %ERRORLEVEL% | Expands to the current ERRORLEVEL. |
| %CMDCMDLINE% | Expands to the original command line that invoked the Command Processor. |
Frequently Asked Questions Regarding The Windows 2000 Command Processor
if condition dosomething ... if not condition dosomething ... rem Check equality if %a% == %b% dosomething ... goto label ... :label ... rem For loop for %%f in (*.java) do javac %%f ... for %%d in (dir_a,dir_c,dirb) do dir %%d: ... rem Call a second script call batfile
Handling of the return code from a program
program_name if errorlevel 1 goto error ... goto end :error echo Program error :end
To run a program in the background (& equivalent):
start program_name