A batch file is a script that executes under the MS-DOS command interpreter, typically having a .BAT extension. Batch files are just a list, or batch, or normal DOS commands, although when in this form they collectively make up what is called batch language. Batch files can be simple programs that can simplify or automate repetitive tasks. While not as powerful as a real scripting language, like sh, it is technically complete.

Some MS-DOS commands are designed to work specifically within batch files, although they may have some limited functionality from a normal command line. These commands include IF, FOR, GOTO, SHIFT, CALL, ECHO, and REM.

Unlike Unix shells, DOS, by default, will display each command in a batch file before it executes, as if it had been entered by a human. This functionality, which, while helpful for debugging a batch file, produces an ugly finished product, may be suspended by using the ECHO OFF command. Although a batch file is just a list of commands, usually a batch file is distinguished by the first command being @ECHO OFF; the leading @ will prevent that line from being displayed, in addition to the supression of subsequent line echo caused by that line.

The AUTOEXEC.BAT file is a special batch file that is executed on system boot. Or, more correctly, it is executed when COMMAND.COM is run with with a /P flag.

The Windows NT command interpreter, CMD.EXE, supports a greatly enhanced, although vastly more clumsy, version of the batch language, most notably in the FOR command, as well as in the addition of commands like SETLOCAL and ENDLOCAL.

OS/2 also supports batch files. Those with a .BAT extension are executed by the MDOS command interpreter, COMMAND.COM. Those with a .CMD suffix are executed by the native OS/2 command interpreter, CMD.EXE. .CMD-suffixed files may also be REXX programs, which are also executed natively under OS/2.

The concept of batch files is one of the oldest in computing. Before personal computers and interactive, terminal-based operating systems were used, almost all input to operating systems was so-called batch processing. Batch, in this context, is named after a batch of punch cards, which contained things like program source code, data and JCL, the system's job control language. Nowadays, the term could be applied to any non-interactive list of commands.

Modern mainframe applications still use some kind of batch processing, examples being statistics gathering whic can take place when the load on the database is low (usually at night) and which would take too long to run online on demand.

Log in or register to write something here or to contact authors.