Jump to content

Batch files: Difference between revisions

From EDM2
Ak120 (talk | contribs)
 
(25 intermediate revisions by 2 users not shown)
Line 1: Line 1:
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.
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.


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.
==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.


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. 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.
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.


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.
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
;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 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.
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==
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]].
<div style="column-count:3;-moz-column-count:3;-webkit-column-count:3">
 
*CALL
==Command Language==
*ECHO
{|class="wikitable"
*ENDLOCAL
!Command||CMD||COMMAND||4OS2
*EXTPROC
|-
*FOR
|CALL||x||x||
*GOTO
|-
*IF
|ECHO||x||x||
*PAUSE
|-
*REM
|ENDLOCAL||x|| ||
*SETLOCAL
|-
*SHIFT
|EXTPROC||x|| ||
</div>
|-
|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.
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 Batch file commands
* [[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==
<div style="column-count:3;-moz-column-count:3;-webkit-column-count:3">
*@
*@
*%?
*%?
* %?%
* %?%
*CALL
*ECHO
*FOR
*GOTO
*IF
*PAUSE
*REM
*SET
*SET
*SHIFT
 
</div>
;Text editors with batch file support
;OS/2 text & programmers editors with DOS batch file support
* [[Boxer]] - Support built in
* [[Boxer]] - Support built in
* [[FTE]] - Has support for syntax highlighting, code folding and syntax-aware autoindent. - Open source - Current.
* [[FTE]] - Has support for syntax highlighting, code folding and syntax-aware autoindent.
* [[jEdit]] - Java based editor - DOS Batch file syntax highlighting built in - Current.
 
==Publications==
[[Image:OS2bftg.jpg|right|150px]]
;OS/2
*Busch: ''Supercharging OS/2: Batch Files and Utilities'' – Addison-Wesley 1988, ISBN 0-201-13785-2
*[[Ronny Richardson]]: ''MS-DOS Batch File Programming Including OS/2'' – TAB Books 1988, ISBN 0-8306-2928-9
*Ronny Richardson: ''OS/2 Batch Files to Go'' - Windcrest/McGraw-Hill 1994, ISBN 0-8306-4589-6
: This appears to be an "OS/2ified" version of the DOS title "Batch Files To Go: A Programmer’s Library"
*Ronny Richardson: ''OS/2 Batch Files to Go'' – McGraw-Hill 1994, ISBN 0-07-052369-X
*Ronny Richardson: ''The Ultimate Batch File Book!'' - McGraw-Hill 1995, ISBN 0-07-912051-2
:Has OS/2 and Win95 information in addition to DOS batch files.


;DOS text & programmers editors with DOS batch file support
;DOS
* [[Boxer]] - Support built in
*Ronny Richardson: ''MS-DOS Batch File Programming'' - Fourth Edition - Windcrest/McGraw-Hill 1993, ISBN 0-8306-4588-8
* [[FTE]] - Has support for syntax highlighting, code folding and syntax-aware autoindent. - Open source - Current.
: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==
==Links==
* Roger Orr: [http://www.howzatt.demon.co.uk/articles/21oct96.html Extending OS/2 Batch Files] - Uses very simple REXX files as an example
* [http://www.jrtinfo.com/Help/Os2Bat.php JaTomes OS/2 Batch file commands] - Fairly exhaustive  
* [http://www.jrtinfo.com/Help/Os2Bat.php JaTomes OS/2 Batch file commands] - Fairly exhaustive  
* [http://www.robvanderwoude.com/batchfiles.php Rob van der Woude's Scripting site] - Has lots of info
* [http://www.robvanderwoude.com/batchfiles.php Rob van der Woude's Scripting site]


[[Category:Programming Languages]][[Category:Batch files]][[Category:File formats]][[Category:REXX]]
[[Category:Programming Languages]][[Category:Batch files]]

Latest revision as of 13:27, 25 February 2020

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

OS/2
  • Busch: Supercharging OS/2: Batch Files and Utilities – Addison-Wesley 1988, ISBN 0-201-13785-2
  • Ronny Richardson: MS-DOS Batch File Programming Including OS/2 – TAB Books 1988, ISBN 0-8306-2928-9
  • Ronny Richardson: OS/2 Batch Files to Go - Windcrest/McGraw-Hill 1994, ISBN 0-8306-4589-6
This appears to be an "OS/2ified" version of the DOS title "Batch Files To Go: A Programmer’s Library"
  • Ronny Richardson: OS/2 Batch Files to Go – McGraw-Hill 1994, ISBN 0-07-052369-X
  • Ronny Richardson: The Ultimate Batch File Book! - McGraw-Hill 1995, ISBN 0-07-912051-2
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