Jump to content

Batch files

From EDM2

Batch files are text files that are used to execute system commands in sequence. Those include all commands you can use 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.

The OS/2 system natively runs OS/2 batch files that have the the file extension CMD and if you have the DOS subsystem installed and activated the system also runs any DOS batch file, which in turn have the extension BAT. If you do not have the DOS subsystem installed on your system you can also run DOS batch files from an emulator such as DOSBox, but you will lose all the nifty integration features that the OS/2 DOS subsystem has to offer. 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, and 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.

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 replacement shells have an batch language very similar to the OS/2-DOS language but with extensions, the 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 programing 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 or word processor 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.

OS/2 Batch file commands

  • CALL
  • ECHO
  • ENDLOCAL
  • EXTPROC
  • FOR
  • GOTO
  • IF
  • PAUSE
  • REM
  • SETLOCAL
  • SHIFT

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.

OS/2 text & programmers editors with OS/2 batch file support
  • Boxer - Support built in
  • FTE - Has support for syntax highlighting, code folding and syntax-aware autoindent. - Open source - Current.
DOS text & programmers editors with OS/2 batch file support
  • Boxer - Support built in
  • FTE - Has support for syntax highlighting, code folding and syntax-aware autoindent. - Open source - Current.

DOS Batch file commands

  • @
  • %?
  • %?%
  • CALL
  • ECHO
  • FOR
  • GOTO
  • IF
  • PAUSE
  • REM
  • SET
  • SHIFT
OS/2 text & programmers editors with DOS batch file support
  • Boxer - Support built in
  • FTE - Has support for syntax highlighting, code folding and syntax-aware autoindent. - Open source - Current.
  • jEdit - Java based editor - DOS Batch file syntax highlighting built in - Current.
DOS text & programmers editors with DOS batch file support
  • Boxer - Support built in
  • FTE - Has support for syntax highlighting, code folding and syntax-aware autoindent. - Open source - Current.

Publications

  • Busch: Supercharging OS/2 : Batch Files and Utilities – Addison-Wesley 1988, ISBN 0-201-13785-2
  • Richardson: MS-DOS Batch File Programming Including OS/2 – TAB Books 1988, ISBN 0-8306-2928-9
  • Richardson: OS/2 Batch Files to Go – McGraw-Hill 1994, ISBN 0-07-052369-X - Reprint of the book below
  • Ronny Richardson: OS/2 batch files to go - 1994 - Windcrest/McGraw-Hill - Paperback, 348 pages - ISBN 0830645896 - ISBN 978-0830645893 - Out of print
  • Ronny Richardson: The Ultimate Batch File Book! - McGraw-Hill - June 1995 - Paperback, 448 pages + CD-ROM - ISBN 0079120512 - ISBN 978-0079120519 - Out of print.

Links