REXX makes it easy to issue commands. The basic rule is that whatever REXX cannot process, it passes to the default environment. You can:
REXX processes your program one clause at a time. It examines each clause to determine if it is:
.array~new
say 'Type total number'
or
pull input
price = cost * 1.2
If the clause is none of the above, REXX evaluates the entire clause as an expression and passes the resulting string to OS/2.
If the string is a valid OS/2 command, OS/2 processes it as though you had typed the string at the command prompt and pressed the Enter key.
The following example shows a REXX clause that uses the DIR command to display a list of files in the current directory.
/* display current directory */say 'DIR command using REXX' dir
The clause dir is not a REXX instruction or a label, so REXX evaluates it and passes the resulting string to OS/2. OS/2 recognizes the string DIR as one of its commands and processes it.
Letting REXX evaluate the command as an expression might cause problems, however. Try adding a path to the DIR command in the above program (such as, dir c:\config.sys). The OS/2 command in this case is an incorrect REXX expression. The program ends with an error.
A safer way to issue commands is by enclosing the command in quotes, which makes the command a literal string. REXX doesn't evaluate the contents of strings. Because the string isn't a REXX instruction or label, REXX passes the string to OS/2. Here is an example using the PATH command:
/* display current path */ say 'PATH command using REXX' 'path'
The next example, DP.CMD, shows a program using the DIR and PATH commands. The PAUSE command is added to wait for the user to press a key before issuing the next instruction or command. Borders are added too.
/* DP.CMD -- Issue DIR and PATH commands to OS/2 */ say '='~copies(40) /* display line of "="'s */ /* for a border */ 'dir' /* display listing of */ /* the current directory */ 'pause' /* pauses processing and */ /* tells user to "Press */ /* any key to continue." */ say '='~copies(40) /* display line of '=' */ 'path' /* display the current */ /* PATH setting */
REXX displays the following on the screen when you run the program.
[C:\]dp ======================================== The volume label in drive C is OS2. Directory of C:\EXAMPLES . <DIR> 10-16-94 12:43p .. <DIR> 10-16-94 12:43p EX4_1 CMD nnnn 10-16-94 1:08p DEMO TXT 117 10-16-94 1:10p 4 File(s) 12163072 bytes free Press any key when ready . . . ======================================== PATH=C:\OS2;C:\OS2\UTIL;C:\OS2\INSTALL [C:\]