Batch file

From Wikipedia, the free encyclopedia

(Redirected from DOS batch file)
Jump to: navigation, search
Microsoft Batch File
File extension: .bat .cmd .btm
Type of format: Scripting

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. Batch files are useful for running a sequence of executables automatically and are often used by system administrators to automate tedious processes.

Although a batch file is analogous to a shell script in Unix-like operating systems the limited syntax and commands means that they are less suited for general-purpose programming. These limitations lead to the widespread use of "enhancement" commands such as those in the Norton Utilities and later the replacement shell 4DOS in the DOS era.

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. There is no difference between the .BAT and .CMD extensions when the file is directly executed. However, when a shortcut is used to launch them, .BAT files run commands using the 16-bit COMMAND.COM command processor whereas if the extension is .CMD, the batch commands are run using the 32-bit Windows NT cmd.exe with all command extensions enabled. Also, the Windows 9x family only recognizes .BAT extension.

Contents

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 which in turn took much of their inspiration from TOPS-10 and TOPS-20 from Digital Equipment Corporation.

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 generally compatible with COMMAND.COM, although a few MS-DOS features are not available. However, cmd.exe provides many additional features and commands not included with MS-DOS or the MS-DOS-based versions of Windows. COMMAND.COM is still present under Windows NT operating systems for better backward compatibility.

The limitations of the original batch file language led to various non-Microsoft interpreters to provide enhanced syntax; the most well-known of which is was 4DOS.

To prevent batch files from being altered, and to hide the source code, a compiler can be used, although none has ever been provided by Microsoft.

Although the IBM OS/2 operating system did support DOS-style batch files, it contained a version of REXX — a much more advanced scripting language.

For complex tasks, from Windows 98 onwards most versions of Windows included Windows Script Host, which allows the running of scripts written in VBScript and related scripting languages. Microsoft have also now created a further, unrelated, scripting tool in Windows PowerShell. The open source scripting languages Perl, Python, and others are now also readily available; and generally for no cost.

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

Wikibooks
Wikibooks' Guide to Windows commands has more about this subject:
Advanced Search
Included Web Search Engines


Safe Search

close

Top Matching Results

Occasionally Search.com will highlight specialized results that are based on the context of your query. Examples of specialized results include specific links to news, images, or video.

Top Matching Results may highlight information from other Search.com pages, content from the CNET Network of sites, or third party content. The listings are based purely on relevance. Search.com does not receive payment for listings in this section but our partners that provide this data may get paid for listing these products.

Sponsored Links

This section contains paid listings which have been purchased by companies that want to have their sites appear for specific search terms and related content. These listings are administered, sorted and maintained by a third party and are not endorsed by Search.com.

Search Results

Search.com sends your search query to several search engines at one time and integrates the results into one list which has been sorted by relevance using Search.com's proprietary algorithm. You can customize the list of search engines included in your metasearch from the preferences.

The search engines that are used in your metasearch may allow companies to pay to have their Web sites included within the results. To view the Paid Inclusion policy for a specific search engine, please visit their Web site. Search.com does not accept payment or share revenue with any search engine partner for listings in this section.