BATCH FILE

(Redirected from DOS batch file)

In MS-DOS, OS/2, 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.
Batch files are useful for running a sequence of executables automatically. Many system administrators use them to automate tedious processes. Although batch files support elementary program flow commands such as ''if'' and ''goto'', they are not well-suited for general-purpose programming.
DOS batch files have the filename extension .BAT. Batch files for other environments may have different extensions, e.g. .CMD in Windows NT and OS/2, or .BTM in 4DOS and related shells.

Contents
History
Example
Uses in virus writing
External links

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.
The MS-DOS operating system's batch program interpreter is 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. In MS-DOS, the most commonly used batch file was AUTOEXEC.BAT, a special batch file that is executed during the booting process.
The newest versions of Windows, Windows 2000 and XP,and Windows Vista are not based on MS-DOS, but on Windows NT. NT-based systems include the cmd.exe command-line interpreter, which is somewhat compatible with COMMAND.COM. 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 'backward' 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. However, OS/2 evolution assumed replacement of .BAT files with REXX scripting.

Example


An example of a simple batch file:
rem echo off prevents the printing of each command to standard output.
@echo off
rem echo. prints a blank line.
echo.
echo Hello World, press any key to start AProgram.exe!
pause > nul
rem The first argument to the batch file can be referenced with "%1"
AProgram.exe %1
if errorlevel 1 goto error
echo.
echo AProgram has finished whatever it was doing.
goto end
:error
echo.
echo Something went wrong with AProgram.
:end

Uses in virus writing


Batch files have become popular for creating viruses, especially among script kiddies. This is due to the simple syntax, the low amount of programming knowledge required to use it and the fact that batch files will run on almost every Windows computer. While some more advanced virus writers might laugh at the simplicity of batch file viruses, they can cause large amounts of destruction very quickly (deleting the contents of the hard disk drive can be done with one command).

External links



Microsoft Windows XP Batch file reference

Windows batch file command overview

FreeDOS' FreeCOM : complete feature list

MS-DOS+Win../95/98/Me batch programming links

Windows Command Line Interface script programming links

This article provided by Wikipedia. To edit the contents of this article, click here for original source.

psst.. try this: add to faves