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:
C:\Rexx>rexx Syntax: REXX [-v] ProgramName [parameter_1....parameter_n] or : REXX [-e] ProgramString [parameter_1....parameter_n] C:\Rexx>
To run the program greeting.rex, for example, use the command
rexx greeting.rexor
rexx greetingIf 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. http://www.oorexx.org/license.html C:\Rexx>
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> 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 C:\Rexx>
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.