Batch files
This page was last modified 13:58, 1 June 2020 by Mars2000you. Based on work by Gdx.

Contents

Description

A batch file is a script file that can contain a series of commands to be executed by the command-line interpreter. All MSX-DOS Internal Commands (included in COMMAND2.COM) and external commands (see MSX-DOS 1 Tools and MSX-DOS 2 Tools) can be used.

Batch files can be edited and stored with a plain text editor. Since MSX-DOS 2 v2.31 batch files text can be coded in Shift-JIS for Japanese MSXs that support Kanji.

You can display the contain of a batch file with the TYPE command.

Enter the names of the batch file from command-line interpreter to execute it. Name extension can be omitted if no command file with the same name is present into the same folder.

Batch file interpreter executes each line in turn, starting with the first. The lines starting with the ECHO command are normally not displayed, but you can use SET ECHO ON to display them.

Filename extensions

Only .BAT extension is supported in MSX-DOS 1 and MSX-DOS 2 with COMMAND2.COM 2.2x and 2.3x.

.BTM files are accepted since COMMAND2.COM 2.4x. These are read into memory completely (max. size 16kb, min. 16kb of free memory must be available) before execution. So scripts execution is faster and the commands END, GOSUB, GOTO, RETURN and labels are possible within these .BTM files.

Batch file parameters (MSX-DOS 2)

COMMAND2.COM supports a number of special variables (%0, %1, ..., %9) in order to refer to the path and name of the batch job and the first nine calling parameters from within the batch job.

Since version 2.40, this number of 9 parameters has been increased to 255. Besides, %n& is available, which means every parameter from parameter n. n defaults to 1, so %& is the same as %1&. %n and %n& are also applicable to aliases.

Non-specified parameters are replaced by a zero-length string. They can be used similar to environment variables, but are not stored in the environment.

Special symbols (MSX-DOS 2)

@ symbol at start of any line prevents the prompt from displaying that command as it is executed.

^ symbol allows to put a second command on the same line.

Quit the batch file execution

Batch file execution ends after the last line has been executed. Since MSX-DOS 2, the execution can also end with the command EXIT 0.

Special filenames

Batch file named AUTOEXEC.BAT (MSX-DOS 1~) or REBOOT.BAT (MSX-DOS 2~) is auto-executed at DOS start when present into root directory of boot disk.