Running a Rexx Program

Rexx programs should have a file extension of .rex (the default searched for by the ooRexx interpreter). Here is a typical Rexx program named greeting.rex. It prompts the user to type in a name and then displays a personalized greeting:

/* greeting.rex - 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 */

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. In this case, the message is the literal string "Please enter your name.". The data between the quotes is a constant and will appear exactly as typed. You can use either single (') or double quote (") delimiters for literal strings.

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 the operation system command prompt. EXIT can also return a value. In our example, 0 is returned. The EXIT instruction is optional. Running off the end of the program is equivalent to coding "EXIT 0".

You can terminate a running Rexx program by pressing the Ctrl+Break key combination. Rexx stops running the program and control returns to the command prompt.

Rexx programs are often run from the command line, although, on the Windows operating systems there are several other options. These options are discussed several paragraphs later. The ooRexx interpreter is invoked by the command, rexx. With no arguments, the command produces a simple syntax reminder:


Syntax: REXX [-v] ProgramName [parameter_1....parameter_n]
or    : REXX [-e] ProgramString [parameter_1....parameter_n]


To run the program greeting.rex, for example, use the command

rexx greeting.rex
rexx greeting
If not provided, an extension of ".rex" is assumed.

The -v option produces the version and copyright infomation. For example:

C:\Rexx>rexx -v
Open Object Rexx Version 4.0.0
Build date: Jul 16 2009
Addressing Mode: 64

Copyright (c) IBM Corporation 1995, 2004.
Copyright (c) RexxLA 2005-2009.
All Rights Reserved.
This program and the accompanying materials
are made available under the terms of the Common Public License v1.0
which accompanies this distribution.

The -e accepts a complete Rexx program in the form of a single string and executes it immediately. Enclose the string in double quotes and separate lines of the program with semi-colons. Arguments can follow the string:

C:\Rexx>rexx -e "use arg name; say 'Hello to you' name" Mark
Hello to you Mark


C:\Rexx>rexx -e "parse arg a b; say a '*' b 'is' a*b" 12 3
12 * 3 is 36

C:\Rexx>rexx -e "parse arg a b; say a '*' b 'is' a*b" 22 -1
22 * -1 is -22

C:\Rexx>rexx -e "parse arg a b; say a '*' b 'is' a*b" 126 456
126 * 456 is 57456


On Windows only there are these additional ways to run your Rexx programs: