Share on Facebook Share on Twitter Email
Answers.com

DOS batch file

 

A file of DOS commands that are "batch" processed one after the other. Windows also supports batch files (see Windows batch file), which are mostly identical to the DOS commands.

To create a DOS batch file, use a text editor such as Edit. If you use a word processor, save your batch file as an ASCII text file, not as a standard document. Always include a .BAT extension with your batch file name.

The following batch file switches to the E drive, goes to the PAT directory and runs the MYPROG program:

         e:
         cd \pat
         myprog

If the file above was named PAT.BAT in the BATCH directory on drive C, you would execute it by typing:

        C:\BATCH>pat

Tip!

If you use batch files to launch applications such as in the example above, make a hard disk directory called BATCH or BAT and put all your batch files in it. Also make sure that the batch files directory is named in the Path command in your AUTOEXEC.BAT file (see DOS Path name) so that you can execute your batch files from whichever directory you're currently in; for example:

          C:\BATCH>pat
          D:\XYZ>pat
          E:\BUDGETS>pat

If you create a batch file that works with files in only one directory, then place the batch file in that directory. When you want to run it, go to that directory.

Stopping a Batch File

To stop a batch file in operation, press Ctrl-C or Ctrl-Break.

Quick Reference

The following commands are for quick reference only. If you are not an experienced batch file programmer, consult a good book on the subject, such as Kris Jamsa's "DOS Batch File Power" published by SAMS.

  cls        Clear the screen
  rem        Remarks
  ::         Remarks
  echo off   Turn off display
  @echo off  Turn off display (3.3 and up)
  echo on    Turn on display
  echo       Display message; for example,
              echo Press any key to continue.
  call       Call other batch file
  pause      Stop (wait for keystroke)
  choice     (DOS 6) a way to get user input

  if not exist filename goto :line
  if not string1==string2 goto :line
  if not errorlevel 0 goto :line
  for %%varname in (files) do command
  %0        - Batch file name
  %1 - %9   - Input variables
  %varname% - Variable used with Set

Following is an example of the choice batch file command in DOS 6. It loads three different programs depending on receiving A, B or C from the user. If A is entered, errorlevel is 1, B is 2 and C is 3. IF ERRORLEVEL always tests for >=, which is why the largest number is tested first.

   choice /c:abc  Run A.  Run B.  Run C.
   if errorlevel 3 goto runC
   if errorlevel 2 goto runB
   :runA
   run program A
   goto end
   :runB
   run program B
   goto end
   :runC
   run program C
   :end

Download Computer Desktop Encyclopedia to your iPhone/iTouch

Search unanswered questions...
Enter a question here...
Search: All sources Community Q&A Reference topics
 
 

 

Copyrights:

Computer Desktop Encyclopedia. THIS DEFINITION IS FOR PERSONAL USE ONLY.
All other reproduction is strictly prohibited without permission from the publisher.
© 1981-2010 The Computer Language Company Inc.  All rights reserved.  Read more