About REXX and ZOC |
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 |
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! |
General Considerations |
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):
| |
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.
|
A Small Example |
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? |
← Back to Programming ZOC (REXX/DDE)