Jump to content

Batch files

From EDM2
Revision as of 07:55, 16 January 2016 by Reiknir (talk | contribs)

Batch files are text files that are used to execute system commands in sequence. Those include all commands you can use from a command line window, 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 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 4OS2/DOS batch files use the BTM file extension. Command line shells ported from the UNIX world will allows 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.

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
DOS text & programmers editors with OS/2 batch file support

DOS Batch file commands

  • @
  • %?
  • %?%
  • CALL
  • ECHO
  • FOR
  • GOTO
  • IF
  • PAUSE
  • REM
  • SET
  • SHIFT
OS/2 text & programmers editors with DOS batch file support
DOS text & programmers editors with DOS batch file support

Links