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.
The ooRexx interpreter is invoked by the command
rexx
To run the program greeting.rex, for example, use the command
rexx greeting.rex
or
rexx greeting
If not provided, an extension of ".rex" is assumed.
On Windows only there are these additional ways to run your Rexx programs:
The installation program on Windows sets up a file association for the .rex file extension. This association allows the ooRexx programs to be run from Windows Explorer by double-clicking on the icon of the program file. In addition, the program can be run from a command prompt in a console window by simply typing the file name. The .rex extension is not needed. For example, simply type greeting to execute the greeting.rex program:
C:\>greeting Please enter your name. Mark Hello MARK C:\>
A Rexx program can be run in silent mode by using rexxhide. This executes the program without creating a console window. This is most useful when creating a program shortcut. For the shortcut target, enter rexxhide.exe followed by the program name and the program arguments. Double-clicking on the shortcut then runs the program without creating a console window. Note that silent means there is no output from the Rexx program. When your program is run by rexxhide, either by double clicking on its icon, or from within a console window, there is no output displayed. Therefore rexxhide would not normally be used for programs like greeting.rex. This is what the greeting.rex program would look like when executed through rexxhide:
C:\>rexxhide greeting.rex C:\>
As a compliment to rexxhide is the rexxpaws program. When a Rexx program is executed through rexxpaws, at completion of the Rexx program, there will be a pause waiting for the user to hit the enter key. For example, using the greeting.rex program, rexxpaws would produce the following:
C:\>rexxpaws greeting.rex Please enter your name. Mark Hello MARK Press ENTER key to exit... C:\>rexxpaws is useful for running a Rexx program from a shortcut, where the program does produce output. On Windows, when double-clicking on the program file icon, a console window opens, the program is run, and then the console window immediately closes. rexxpaws prevents the console window from closing until the user hits the enter key. This allows the user to see what output the program produced.