CMD

From C64-Wiki
Jump to: navigation, search
Disambiguation The title of this article is plurivalent. CMD (Disambiguation).
BASIC keyword
Keyword: CMD
Abbreviation: C Shift+M
Type: Command
Token code: -/$-
Handling routine
in BASIC ROM:
-–-
$-–-
List of all BASIC keywords


Remark: This article describes the BASIC-Command CMD in BASIC V2 at the Commodore 64.

Type: Command
General Programming-Syntax: CMD "<logical filenumber>"[,[string][;]]

The BASIC-command CMD changes the data output from the screen to another peripheral device like datasette, modem, printer or disk drive. CMD can be used directly or in programs. The logical filenumber can have values from 1 until 255 (reasonably <128) and must be selected with the BASIC-Command OPEN. When CMD is used without previous OPEN command, the BASIC-error "?FILE NOT OPEN ERROR" is reported. The logical filenumber used with CMD must be the same as in the previous OPEN command.

When the BASIC-Command CMD is executed, all PRINT- and LIST-commands are performed on the selected peripheral device. With the command PRINT#<logical filenumber> the data output can be returned to the screen before the device is closed with the BASIC-Command CLOSE<logical filenumber>.

When a BASIC-error occurs, the data output is returned to screen, too, but Space characters keep being sent to the logical file of the selected device. So the commands PRINT#1 and CLOSE must be executed for a correct abort of CMD.

Examples[edit]

OPEN 1,4,7: CMD 4, "Test on printer capital/small letters in  program listing X": PRINT: LIST 
(Redirecting of a BASIC program listing to a printer in capital/small letters) PRINT#1: CLOSE 1
(finishing redirecting of the data output)
10 REM Writing of a sequential file with 50 chars on datasette.
20 OPEN 1,1,1, "TESTFILE": CMD 1
30 FOR X=1 TO 50: PRINT X: NEXT X
40 PRINT#1: CLOSE 1

A demonstration of the crucial function of the semicolon in line number 110 and 140:

100 OPEN 3,3
110 CMD 3,"TEST";
120 PRINT "TEXT"
130 PRINT "DEMO"
140 PRINT #3,;
150 CLOSE 3
160 PRINT "END";

This is the output on screen:

RUN
TESTTEXT
DEMOEND
READY.
BASIC V2.0 (second release) Commands

ABS | AND | ASC | ATN | CHR$ | CLOSE | CLR | CMD | CONT | COS | DATA | DEF | DIM | END | EXP | FN | FOR | FRE | GET | GET# | GOSUB | GOTO | IF | INPUT | INPUT# | INT | LEFT$ | LEN | LET | LIST | LOAD | LOG | MID$ | NEW | NEXT | NOT | ON | OPEN | OR | PEEK | POKE | POS | PRINT | PRINT# | READ | REM | RESTORE | RETURN | RIGHT$ | RND | RUN | SAVE | SGN | SIN | SPC | SQR | STATUS/ST | STEP | STOP | STR$ | SYS | TAB | TAN | THEN | TIME/TI | TIME$/TI$ | TO | USR | VAL | VERIFY | WAIT