COMMAND.COM help Contents 1. What is COMMAND.COM 2. Internal commands 3. Environment variables 4. STDIO redirection 5. Arguments to batch files 6. Tips and tricks 1. What is COMMAND.COM COMMAND.COM is the default command interpreter of ST-DOS. It is the main tool for interaction between the user (human) and the operating system (computer). COMMAND.COM is a command line based tool that can run programs and batch files and tweak some internal variables of the kernel. 2. Internal commands 2.1. DIR Function: Writes a list of files in the current working directory to STDOUT. Required arguments: None Options: /P: Waits for a keypress after each screenful of information. /S: Also lists files in subdirectories. [filename with wildcards]: Lists only files whose names match this filename. Example: DIR *.TXT 2.2. EXIT Function: Exits the command prompt. Required arguments: None Options: /B: Only stops the current batch script. [number]: Return value of the COMMAND.COM process or the batch script. Example: EXIT 1 2.3. TYPE Function: Writes the contents of a file to STDOUT. Required arguments: Filename Options: /P: Waits for a keypress after each screenful of information. Example: TYPE AUTOEXEC.BAT 2.4. CD Function: Changes the current working directory. Required arguments: Path to the new working directory Options: None Example: CD GAMES 2.5. SET Function: Lists or edits environment variables. Required arguments: None when examining the already existing environment. A name of an environment variable with its new value when editing the environment. Options: None Examples: SET TEMP=C:\TEMP SET PATH=C:\PROGRAMS;%PATH% 2.6. TIME Function: Writes the current time to STDOUT and asks for a new time. If the user just presses the ENTER key, the time is not changed. Required arguments: None Options: None Example: TIME 2.7. DATE Function: Writes the current date to STDOUT and asks for a new date. If the user just presses the ENTER key, the date is not changed. Required arguments: None Options: None Example: DATE 2.8. CLS Function: Clears the screen. Required arguments: None Options: None Example: CLS 2.9. ECHO Function: Echoes a line of text to STDOUT, or specifies whether the commands in a batch file are echoed to STDOUT or not. Required arguments: Line of text when echoing a line of text to STDOUT. on/off when changing the setting of batch command echo. Options: None Example: ECHO Hello World! 2.10. DEL Function: Deletes a file. Supports wildcards. Required arguments: Filename Options: None Example: DEL *.TMP 2.11. COPY Function: Copies files. Supports wildcards. Required arguments: Source and target. If the target is a directory, the name of the target file is the same as the name of the source file. Options: None Example: COPY *.TXT A: 2.12. MKDIR Function: Creates a directory. Required arguments: Name of the new directory. Options: None Example: MKDIR MY_FILES 2.13 RMDIR Function: Removes a directory. The directory must be empty. Required arguments: Name of the directory. Options: None Example: RMDIR WINDOWS 2.14. RENAME Function: Renames a file or a directory. Can also be used to move a file to a different directory in the same file system. Required arguments: Name of the file to be renamed, and the new name. Options: None Example: RENAME AUTOEXEC.BAT AUTOEXEC.BAK 2.15. REM Function: Do nothing. Can be used to add comments to batch scripts. Required arguments: None Options: None Example: REM This line does nothing in a batch file. 2.16. VERIFY Function: Toggle verify flag on/off. When the verify flag is on, the kernel uses the "verify sectors" function of the BIOS after each disk write. Useful with unreliable floppies. Required arguments: None when the user wants to know the current state of the verify flag. 1 or 0 to set the verify flag. Options: None Example: VERIFY 1 2.17. IF Function: Do something on condition. Required arguments: A condition and a command to execute when the condition is satisfied. Options: None Possible conditions: EXIST [filename]: Returns true when [filename] exists in the current working directory. [str1]==[str2]: Returns true when [str1] is identical to [str2]. ERRORLEVEL [number]: Returns true when ERRORLEVEL has at least the value of the [number]. NOT negates the condition. Examples: IF EXIST test.txt ECHO test.txt exists. IF %COMDRV%=C ECHO COMMAND.COM has been executed from the C drive. IF NOT ERRORLEVEL 1 ECHO ERRORLEVEL is 0. IF ERRORLEVEL 1 ECHO ERRORLEVEL is at least 1. 2.18. GOTO Function: Jumps to a label in a batch file. Labels begin with a colon (:). Required arguments: Name of the label. Options: None Example: GOTO END ... :END 2.19. CALL Function: Calls a batch script. Returns to the current batch file after the called batch script has finished. Required arguments: File name of the batch script. Options: None Example: CALL BATCH.BAT 2.20. VER Function: Prints DOS version information to STDOUT. Required arguments: None Options: None Example: VER 2.21. BUFFERS Function: Changes the maximum size of file buffers. Required arguments: None if the user wants to see the current maximum size. Count of bytes to change the maximum size of file buffers. Options: None Example: BUFFERS 65535 2.22. MOVE Function: Moves a file to another directory. Supports wildcards. Required arguments: Source and target. The target can be a directory. Options: None Example: MOVE OLDTEXT.TXT C:\OLDFILES\ 2.23. CACHE Function: Enables or disables block caches. Required arguments: 1 if the user wants to enable caches. 0 if the user wants to disable caches. Options: None Example: CACHE 0 2.24. SYSDEBUG Function: Enables or disables messages about unsupported system calls. Required arguments: 1 if the user wants to see a message on screen when the program tries to do an unsupported syscall. 0 if the user wants to disable the messages. Options: None Example: SYSDEBUG 1 2.25. HISTORY Function: Prints the previously entered commands to STDOUT or changes the size of the command history. Required arguments: None if the user wants to see the previous commands. A number if the user wants to change the amount of memory allocated for the command history. Options: None Example: HISTORY 16 2.26. EXEC Function: Executes a program and removes COMMAND.COM from the memory. When the program exits, the control is returned to the program that executed COMMAND.COM. Required arguments: Filename of the executable binary. Options: None Example: EXEC MEM.EXE 2.27. FOR Function: Iterate over a set of files. Variable names can be only one byte long. Unlike environment variables in commands, FOR variables have the percent sign only before the variable and not after it. Syntax: FOR %[variable] IN ([filename with wildcards]) DO [command] Examples: FOR %a IN (*.TXT) DO TYPE %a 3. Environment variables By default two environment variables are defined: COMSPEC: Full path to the executable file of the current COMMAND.COM instance. COMDRV: Drive letter of COMSPEC. To replace any part of any command with an environment variable, enclose the name of the variable with percent signs (%). 4. STDIO and redirection 4.1. Piping You can pipe commands using the pipe operator (|). Notice that in a single- tasking operating system like ST-DOS there is no actual pipe syscall - instead the command prompt creates a temporary file where the standard output of the first program is redirected, and that file is then used as the standard input for the next program. This temporary file is created to the directory pointed by the TEMP environment variable, or to the current working directory if it doesn't exist. You need to have enough free space in your filesystem for the temporary file. Example: ECHO test | HEXDUMP 4.2. Redirecting STDOUT to a file STDOUT (file handle 1) can be redirected to a file using the STDOUT redirection operator (>). Two STDOUT redirection operators (>>) can be used to append the output to an already existing file. Using only one STDOUT redirection operator (>) truncates the file if it already exists. Examples: MD5SUM foo.txt > foo.md5 DATE >> foo.txt 4.3. Redirecting STDIN from a file STDIN (file handle 0) can be redirected from a file using the STDIN redirection operator (<). Example: TIME < NUL 4.4. Default STDIO When the kernel starts the first program, it will have three file handles open. By default they all point to the kernel's internal console device. File handle 0 (STDIN) is opened in read-only mode, file handle 1 (STDOUT) is opened in write-only mode and file handle 2 (STDERR) is opened in read-write mode. When COMMAND.COM is started with the /P switch, it reopens the first three file handles using the reserved filename CON. By default CON points to the kernel's internal console device, but if the user has loaded a device driver that uses the same device name, it will override the kernel's default console device. In addition to that, COMMAND.COM tries to open two additional files, AUX and PRN. If either of those files don't exist, NUL is opened instead. By default AUX and PRN don't exist, but you can create them to the root of the system drive as symbolic links to give those filenames a meaning. In the most common use case you might want AUX to point to COM1 and PRN to LPT1. 5. Arguments to batch files Batch files can access their arguments using the numeral variables. Variable %0 has the name of the batch file itself, %1 has the first argument, %2 has the second argument and so on. 6. Tips and tricks If you don't have enough contiguous free memory to run some program, you can use COMMAND.COM to change the working directory to the program's directory and exit COMMAND.COM using the EXIT command. Then you can try executing the problematic program directly from the kernel prompt. That way you have at least 64 kB more contiguous memory, assuming that you haven't started any TSRs from the COMMAND.COM prompt.