Batch file
From Free net encyclopedia
In DOS and Windows, a batch file is a text file containing a series of commands intended to be executed by the command interpreter. When a batch file is run, the shell program (usually command.com
or cmd.exe
) reads the file and executes its commands, normally line-by-line. A batch file is analogous to a shell script in Unix-like operating systems.
DOS batch files have the filename extension .BAT
or .CMD
. AUTOEXEC.BAT
is a special batch file that is executed during the booting process.
Contents |
History
Microsoft DOS and Windows batch programming has evolved along with the product releases of these operating systems. The command interpreters that come with these operating systems provide two distinct modes of work: interactive mode (in which the user types commands at a prompt which are then executed immediately) and batch mode (which executes a predefined sequence of commands). The original concepts for both modes draw ideas from Unix shells, as well as other text-based command line interfaces from the early 1980s such as CP/M.
Originally, the MS-DOS operating system provided a batch program interpreter for the shell command.com
. Batch programs for MS-DOS are composed of a relatively simple set of commands interpreted directly by command.com
(internal commands), and utilities that exist as separate executables (external commands). The evolution of this branch of batch programming proceeded through the releases of MS-DOS, and into Windows 95, Windows 98 and finally Windows Me.
The newest versions of Windows, Windows 2000 and XP, are not based on MS-DOS, but on Windows NT, introduced before MS-DOS 6.0. NT-based systems include the cmd.exe
command-line interpreter, which is somewhat compatible with MS-DOS. Some MS-DOS features are not available, but there are many additional features and commands not included with MS-DOS or MS-DOS-based versions of Windows. Command.com is still present under Windows NT operating systems for better backwards compatibility.
Various non-Microsoft command interpreters exist that provide enhanced batch program command syntax. An example of these is the 4DOS product.
Several non-Microsoft implementations of batch compilers exist to convert batch programs to directly executable programs. The quality-of-implementation of these compilers varies widely.
The IBM OS/2 operating system contains a text based command facility that is related to the ones supplied with Microsoft operating systems.
@echo off
The default behaviour of the shell is to print each command to standard output before executing it. This is usually not desired, so the command echo off
is given at the beginning of a batch file to prevent that from happening. In that form, only the echo off
command itself would be printed. Since individual commands may be prefixed with the @
character to be prevented from printing, most batch files start with the line @echo off
.
Example
An example of a simple batch file:
@echo off echo echo Hello World, press any key to start AProgram.exe! pause > nul call AProgram.exe echo echo AProgram is finished whatever it was doing, have fun today!
See also
External links
- Batfiles: The DOS Batch File Programming Handbook and Tutorial
- Interactive Batch Course by Allenware
- Fpschultze's Batch Scripting Site
- Useful MS-DOS batch files and tricks, T.Salmi
- Tom Lavedas' Batch File Applications
- Simon Sheppard's Windows XP Commandsde:Batchbetrieb
ja:バッチファイル he:קובץ אצווה pl:Program wsadowy pt:Ficheiros batch sv:Batchfil zh:批处理