”;
One of the biggest advantages in Rexx is the ability to create re-usable scripts. Often in organizations nowadays, having re-usable scripts is a big value add in saving time to do common repetitive tasks.
For example, technology teams in an IT organization can have the need to have scripts which do common everyday tasks. These tasks can include interacting with the operating systems. These scripts can then be programmed to handle bad return codes or errors.
Rexx offers a lot of system commands that can be used to perform such repetitive tasks. Let’s look at some of the system commands available in Rexx.
dir
This is the normal directory listing command which is used in Windows.
Syntax
dir
Parameters
None
Return Value
This method returns the current directory listing on the system.
Example
/* Main program */ dir
The output depends on the directory in the system.
The following program is just an example.
Output
Volume in drive D is LENOVO Volume Serial Number is BAC9-9E3F Directory of D: 04/06/2016 12:52 AM 268,205 100008676689.pdf 10/20/2015 08:51 PM <DIR> data 06/01/2016 10:23 AM 31 Example.txt 10/28/2014 06:55 PM <DIR> Intel 06/02/2016 11:15 AM 23 main.rexx 12/22/2014 08:49 AM <DIR> PerfLogs 12/13/2015 11:45 PM <DIR> Program Files 12/24/2015 10:26 AM <DIR> Program Files (x86) 07/17/2015 01:21 AM <DIR> Users 12/23/2015 10:01 AM <DIR> Windows 3 File(s) 268,259 bytes 7 Dir(s) 202,567,680 bytes free
Another example of the dir command is shown in the following program. Only this time we are making use of the special rc variable. This variable is special in Rexx and gives you the status of the execution of system commands. If the value returned is 0, then that means the command is executed successfully. Else the error number will be given in the rc variable name.
Example
/* Main program */ dir if rc = 0 then say ''The command executed successfully'' else say ''The command failed, The error code is ='' rc
When we run the above program we will get the following result.
Output
The command failed, The error code is = 127
Redirection Commands
Rexx also has the facility of using redirection commands. The following redirection commands are available in Rexx.
-
< − This command is used to take in the input which comes from a file.
-
> − This command is used to output the content to a file. If the file does exist, it will be over-written.
-
>> − This is also used to output the content to a file. But the output is added to the end of the file to preserve the existing content of the file.
Let’s look at an example of how we can use redirection commands. In the following example, we are using the sort command to sort a file called sortin.txt. The data from the file is sent to the sort command. The output of the sort command is then sent to the sortout.txt file.
Example
/* Main program */ ''sort <sortin.txt> sortout.txt''
Assume that the file sortin.txt has the following data.
Output
b c a
The file sortout.txt will then have the following data.
a b c
The ADDRESS Function
This method is used to find out what is the default environment used for the Input, Error and Output streams.
Syntax
ADDRESS(options)
Parameters
-
Options for what is the address of a particular system.
Return Value
This method returns the name of the environment for the Input, Error and Output streams.
Example
/* Main program */ say ADDRESS(''I'') say ADDRESS(''O'') say ADDRESS(''E'')
When we run the above program we will get the following result.
Output
INPUT NORMAL REPLACE NORMAL REPLACE NORMAL
”;