Home Page
        Orders     Downloads     Support     Contact     Deutsch
ZOC Terminal is a professional SSH Client and Terminal Emulator for Windows and macOS.
ZOC Online Help Topic:

Programming ZOC (REXX/DDE) → Introduction to ZOC REXX

 

About REXX and ZOC
The scripting language REXX has a long tradition as a scripting language, especially in the IBM world. It is a simple but powerful language which offers all language elements that are necessary for small and medium programming tasks (variables, decisions, loops, procedures, string manipulation, file I/O, etc.). There is even a REXX dialect (OOREXX) which offers object oriented language elements.

For scripting, ZOC uses this solid language as a foundation and extends it by adding specific functions for terminal emulation and communication. All these extensions have names starting with Zoc, e.g. ZocConnect or ZocSend.


 
Note: ZOC's implementation for the REXX interpreter for Windows and macOS is Regina REXX (https://regina-rexx.sourceforge.net/). If you prefer a different implementation (e.g. OOREXX), you can switch to that in Options→Program Settings→Special Files→Alternate REXX-DLL.

 

 

Learning ZOC REXX
To get an impression of the language, you will find a quick tour through the very basics right below.

Once you completed this overview, continue with reading REXX Language Elements and ZOC-REXX Commands. These two topics will cover all language elements which are necessary to perform the majority of your tasks.

Beyond that, you will find the ZocScriptingSamples.zip archive in your My Documents→ZOC8 Files→REXX folder helpful. It contains a series of step-by-step examples with increasing complexity. On our website we then offer even more links to tutorials and samples.

If you want to use REXX on a very sophisticated level, you can look into the full ZOC REXX Reference (PDF), which you will also find in your My Documents→ZOC8 Files→REXX folder.

 

 

Hello World!
ZOC REXX versions of the famous Hello World program looks like this:
 
/* REXX */
-- Display "Hello World" on the local screen
SAY "Hello World!"

 
/* REXX */
-- Send "Hello World" to the remote host
CALL ZocSend "Hello World!"

 
/* REXX */
-- Make a remote Unix host say "Hello World"
CALL ZocSend "echo 'Hello World!'^M"

 

 

General Considerations
Usually all REXX programs begin with a comment, which REXX defines as any text which is written between /* and */. This means that the first line in all REXX programs looks like this: /* REXX */. In addition to that, REXX also knows a form of comment which runs to the end of line. These comments start with -- (see the above samples).

REXX knows native and non-native commands and functions. Examples for native commands are SAY, IF, DO, END. Some of the non-native (ZOC specific) commands are ZocSend, ZocTimeout, ZocDisconnect.

For easier reference, native language elements will written in uppercase, e.g. CALL, SELECT, THEN, SAY. Zoc extension commands are written in CamelCase, e.g. ZocConnect, ZocSend, etc. Finally names which are user defined (for example variables) are set in lowercase characters, result= 10*userinput.

 

 

How to Use Different Types of Commands
       
Native Commands
 

You can use native commands by writing the command name and optional arguments. Their placement is governed by the REXX language syntax and they create the basic structure of the program (the all uppercase words below are all native REXX commands):
 

IF rc=640 THEN DO
    SAY "Call Failed!"
    SIGNAL done
END
ELSE DO
    SAY "Success!"
END
    
EXIT

ZOC-Commands
 

ZOC-commands are executed by means of REXX's subroutine or function call mechanism. Essentially they come in two flavors:

For commands which do not return a result (or if you do not care about the result), you use the CALL command with the name of the ZOC-command and the required arguments separated by commas.

For commands which do return a value, you use an assignment and supply the argument list enclosed in brackets after the command name.
 

-- two commands without return values:
CALL ZocBeep 2
CALL ZocConnect "telnet.hogwarts.edu"
CALL ZocDownload "ZMODEM", "SOMEFOLDER"
    
-- this is a command which returns a value:
answer= ZocAsk("What is your name")
 

 

 

A Small Example
Most of the time you will use REXX to log into a host and do things automatically.

While simple logins sequences can be stored directly in the host directory without scripting (see Changing Host Directory Entries), there is a limit to what these can do.

The example below shows a more complex case. It calls a SSH host and checks for email by issuing the mail command on the host and looking at the result.
 

    
/*REXX*/
    
-- set variables for host login
hostip= "users.hogwarts.edu"
username= "harryp"
password= "alohomora"
    
-- make an SSH connection to the host
CALL ZocSetDevice "Secure Shell"
CALL ZocConnect username":"password"@"hostip
    
-- if login works, we should see the "Last login"
-- message within 10 seconds. (if ZocWait returns 640,
-- it means it did not appear in time)
CALL ZocTimeout 10
x= ZocWait("Last login")
IF x\=640 THEN DO
    -- we are in, so wait for a prompt
    CALL ZocWait "$"
    
    -- send the mail command
    CALL ZocSend "mail^M"
    
    -- skip the echo from our command
    CALL ZocWaitline
    
    -- wait for one more line of output and grab it
    CALL ZocWaitline
    themail= ZocLastline()
    
    -- logout and disconnect
    CALL ZocSend "exit^M"
    CALL ZocDelay 1
    CALL ZocDisconnect
    
    
    /* if the reply from mail was different from "No mail for ..."
     then display a message box to the user */
    IF LEFT(themail,7)\="No mail" THEN DO
        CALL ZocMsgBox themail
    END
END
    
    
    

 
Note: More samples can be found in the ZocScriptingSamples.zip archive.

 

 

What now?
Continue with the more detailed overview of REXX Language Elements.

 
← Back to Programming ZOC (REXX/DDE)

 

Downloads
Orders
Contact
Support
Terms of Use
Privacy Policy