Batch files

From EDM2
Jump to: navigation, search

Batch files are text files that are used to execute system commands in sequence. Those include all commands invoked from a command shell, any external program that is in the PATH or that you specifically point to in a location outside of the path. In addition to small number of commands that are either specific to batch files and do not function inside the command line shell or commands that will function but are not meaningful in normal command line usage.

Implementation

The OS/2 command processor natively runs batch files that have the file extension CMD and with the DOS subsystem installed and activated also runs any DOS batch file, which in turn have the extension BAT. Without the DOS subsystem installed you can also run DOS batch files from an emulator such as DOSBox, but you will lose all the nifty integration features. DOS and OS/2 batch files are for the most part identical except for the fact that the CMD files run inside an OS/2 command shell and the BAT files inside a DOS Command shell. If you have the DOS subsystem installed you can call OS/2 programs from DOS batch files and DOS programs from OS/2 batch files.

Special batch files:

  • OS2INIT.CMD
  • STARTUP.CMD
  • AUTOEXEC.BAT

In addition you can install a number of alternate command line interfaces that either allow you to expand the number of available batch file commands or run completely different types of batch files. Most third party command shells have some sort of batch file functionality built in and some have full scripting languages, the 4OS/2 and 4DOS shells offer a similar batch language with extensions. 4OS/2 and 4DOS batch files use the BTM file extension.

Shells ported from the UNIX world will allow you to run classic sh shell scripts, which are more feature rich than OS/2 style batch files but not quite as powerful as REXX scripts.

While the DOS market saw a huge number of utility programs released that allowed you to extend the functionality of batch files there was never such a market for batch extenders for OS/2 although a few popped up. This is mainly due to the presence of REXX as a component of the OS, but since that is a fully fledged programming language, albeit one that is unusually easy to use, you can in most cases literally create the functions you might want from REXX in less time than it would take you to trace down a third party utility on the net.

File format

The Batch file format is as simple as it gets, no matter if it is a DOS, 4DOS, an OS/2 or 4OS/2 batch file it is always an 8 bit plain text file that adheres to the charset that the system codepage allows at any given time. You can create or edit the file with any text editor that allows you to open and save plain text files, which is just about all of them, if you want the file in another codepage than the system is currently running simply assign another codepage to the program object properties if you run it from the PM, or issue a CHCP XXXx command at the beginning of the file, which is limited to 2 different codepages by adjustments of COUNTRY setting in CONFIG.SYS.

The commands are formatted exactly as they would be from the command line and a carriage return signals that the next line should be processed as the next command in the sequence.

In IBM terminology and therefore in most IBM publications batch file commands on OS/2 are referred to as Command Language which might seem confusing for some readers, this is a vestige from mainframes and minicomputer system where batch files actually came to have something resembling a language, however nothing similar was ever ported or created for OS/2 as IBM was slowly replacing those constructs with REXX.

Command Language

Command CMD COMMAND 4OS2
CALL x x
ECHO x x
ENDLOCAL x
EXTPROC x
FOR x x
GOTO x x
IF x x
PAUSE x x
REM x x
SETLOCAL x
SHIFT x x

In addition the above commands a batch script can call any valid OS/2 program including normal executables, scripts in other languages and system commands. Most batch commands have formatting and options more like a executable than what you would expect from a scripting language. Some batch file commands can also be used from the command line but have limited utility there.

DOS Batch file commands
  • @
  • %?
  •  %?%
  • SET
Text editors with batch file support
  • Boxer - Support built in
  • FTE - Has support for syntax highlighting, code folding and syntax-aware autoindent.

Publications

OS2bftg.jpg
OS/2
This appears to be an "OS/2ified" version of the DOS title "Batch Files To Go: A Programmer’s Library"
Has OS/2 and Win95 information in addition to DOS batch files.
DOS
  • Ronny Richardson: MS-DOS Batch File Programming - Fourth Edition - Windcrest/McGraw-Hill 1993, ISBN 0-8306-4588-8
Updated edition of the above book but misses some OS/2 1.x content.
  • Ronny Richardson: MS DOS Utility Programs: Add-On Software Resources - Windcrest 1989, ISBN 0-8306-9278-9
  • Ronny Richardson: MS-DOS Batch File Utilities - Windcrest 1991, ISBN 0-8306-2482-1
Appears to be an updated version of the above book, even though it is not noted as such on the cover
  • Ronny Richardson: Batch Files To Go: A Programmer’s Library - Windcrest 1992, ISBN 0-8306-3989-6
  • Ronny Richardson: Writing DR DOS Batch Files - Windcrest 1993 - ISBN 0-8306-4244-7
  • Kris Jamsa: MS-DOS Batch Files: Microsoft Quick Reference - Microsoft Press 1990, ISBN 1-55615-235-3
  • Kris Jamsa: MS-DOS Batch Files: Second edition - Microsoft Press 1991, ISBN 1-55615-338-4
  • Kris Jamsa: Concise Guide to Microsoft DOS Batch Files; Third revised edition - Microsoft Press 1993, ISBN 1-55615-549-2
  • Kris Jamsa: Concise Guide to Microsoft DOS Batch Files; Revised edition - Penguin Books 1993 - ISBN 1-55615-638-3
  • Ronny Richardson: Builder Lite: Developing Dynamic Batch Files - Windcrest 1993, ISBN 0-8306-4175-0
Discusses building Batch files with Builder/Builder Lite, a shareware batch file compiler
  • Ronny Richardson: Dr. Batch File's Ultimate Collection - Windcrest 1992, ISBN 0-8306-4113-0
More of a listing and explanation of about 120 utilitarian batch files included on floppy than a tutorial per se.

Links