ADDRESS Instruction

To send a command to a specific environment, use this format of the ADDRESS instruction:

ADDRESS environment expression

For environment specify the destination of the command. To address the Windows environment, use the symbol CMD. For expression, specify an expression that results in a string that Rexx passes to the environment. Here are some examples:

ADDRESS instruction
address CMD "dir" /* pass the literal string */
/* "dir" to Windows */
address "bash" "ls" /* pass the literal string */
/* "ls" to the Linux bash shell */
cmdstr = "dir
/* to a variable */
address CMD cmdstr /* Rexx passes the string */
/* "dir
address edit "rain" /* Rexx passes the "rain" */
/* command to a fictitious */
/* environment named edit */

Notice that the ADDRESS instruction lets a single Rexx program issue commands to two or more environments.

The ADDRESS instruction allows to redirect the command's standard input (stdin), standard output (stdout) and standard error (stderr) files directly to Rexx. The following example will define a command to list all environment variables of the current process, sort it on Unix operating systems and redirect the standard output line by line to a Rexx array which then gets listed by the Rexx program in a DO loop.

Redirecting the standard output to a Rexx array:
parse source os . /* get operating system name */
/* define external command to list all environment variables */
if os~startsWith("Win") then command='set' /* Windows (sorted by default) */
else command='env ¦ sort -f' /* Unix (needs sorting) */
vars=.array~new /* array to store command's output (environment variables) */
/* let the operating system shell execute the command, redirect */
/* command's output (stdout) line by line to our Rexx vars array */
address system command with output using (vars)
len=vars~items~length /* get number of digits/characters */
if rc=0 then /* return code 0: indicates command executed successfully */
do counter i var over vars /* list environment variables one by one */
say "" i~right(len)":" var /* show value of counter i right adjusted */
say "operating system:" os', command was: "'command'", vars:' vars~items

Running the above Rexx program on Darwin (Apple) may yield an output like:

1: Apple_PubSub_Socket_Render=/private/tmp/ 2: HOME=/Users/some_username 3: LC_CTYPE=UTF-8 ... cut ... 20: XPC_FLAGS=0x0 21: XPC_SERVICE_NAME=0 22: _=/usr/bin/env operating system: DARWIN, command was: "env ¦ sort -f", vars: 22

Running the above Rexx program on Linux may yield an output like:

1: CLUTTER_BACKEND=x11 2: CLUTTER_IM_MODULE=xim 3: COLORTERM=truecolor ... cut ... 77: XDG_SESSION_TYPE=x11 78: XDG_VTNR=7 79: XMODIFIERS=@im=ibus operating system: LINUX, command was: "env ¦ sort -f", vars: 79

Running the above Rexx program on Windows may yield an output like:

1: ALLUSERSPROFILE=C:\\ProgramData 2: APPDATA=C:\\Users\\Administrator\\AppData\\Roaming 3: asl.log=Destination=file ... cut ... 50: windir=C:\\WINDOWS 51: windows_tracing_flags=3 52: windows_tracing_logfile=C:\\BVTBin\\Tests\\installpackage\\csilogfile.log operating system: WindowsNT, command was: "set", vars: 52