Running a Rexx Program

Rexx programs should have a file extension of CMD on Windows, just like Batch facility files, or REX (default to prevent confusion with Windows NT files). Here is a typical Rexx program named GREETING.CMD. It prompts the user to type in a name and then displays a personalized greeting:

/* GREETING.CMD - a Rexx program to display a greeting.  */
say "Please enter your name."    /* Display a message    */
pull name                        /* Read response        */
say "Hello" name                 /* Display greeting     */
exit 0                   /* Exit with a return code of 0 */

The program begins with a comment. This is not a requirement, but it is recommended to ensure compatibility with other operating systems, such as OS/2, where the first line in a Rexx program must be a comment line.

The Object Rexx interpreter is invoked by the command

rexx

To run the program MYRexx.CMD, for example, use the command

rexx MYRexx.CMD

If you want to run your Rexx program in silent mode without creating a console window on Windows, you can invoke RexxHIDE.EXE followed by the program name and the program arguments from a program item. If RexxHIDE is called from within a console window, no output is displayed in the console window.

SAY is a Rexx instruction that displays a message (like PRINT in Basic or printf in C). The message to be displayed follows the SAY keyword. The single quotes are necessary to delimit a character string. In this case, the character string is Please enter your name. You can use double quotes (") instead of single quotes.

The PULL instruction reads a line of text from the standard input (the keyboard), and returns the text in the variable specified with the instruction. In our example, the text is returned in the variable name.

The next SAY instruction provides a glimpse of what can be done with Rexx strings. It displays the word Hello followed by the name of the user, which is stored in variable name. Rexx substitutes the value of name and displays the resulting string. You do not need a separate format string as you do with C or Basic.

The final instruction, EXIT, ends the Rexx program. Control returns to Windows or Unix/Linux. EXIT can also return a value. In our example, 0 is returned. The EXIT instruction is optional.

You can terminate a running Rexx program by pressing the Ctrl+Break key combination. Rexx stops running the program and control returns to Windows or Unix/Linux.