(LOGO.JPG) Python for OpenVMS

This example demonstrates the use of several RMS control blocks and services to output the contents of a file to the screen. Note that the file name is hard-coded.


#$% RMS_TYPE.PY
# -----
#  output file's contents to screen

RMS__NORMAL = 65537
RMS__EOF    = 98938

import pyvms, sys, vms_lib, vms_sys

# create a FAB (File Access Block) object
fab = pyvms.vmsobj_fab()
# put filename in FAB
fab.FNA = 'PYTHON_VMS:SETUP.COM'

# open the file
status = vms_sys.open (fab)
if (status != RMS__NORMAL):
    print vms_sys.getmsg (fab.L_STS)[0]
    print vms_sys.getmsg (fab.L_STV)[0]
    sys.exit (1)

# create a RAB (Record Access Block) object
rab = pyvms.vmsobj_rab()
# assign FAB to RAB
rab.FAB = fab

# connect record stream
status = vms_sys.connect (rab)
if (status != RMS__NORMAL):
    print vms_sys.getmsg (rab.L_STS)[0]
    print vms_sys.getmsg (rab.L_STV)[0]
    sys.exit(1)

# allocate a memory buffer and assign to RAB
rab.UBF = pyvms.vmsobj__membuf (30000)

# loop over all records
while (status == RMS__NORMAL):
    # get a record
    status = vms_sys.get (rab)
    # abort loop if end-of-file
    if (status == RMS__EOF):
        break
    # print error if there is one
    if (status != RMS__NORMAL):
        print vms_sys.getmsg (rab.L_STS)[0]
        if (rab.L_STV != 0):
            print vms_sys.getmsg (rab.L_STV)[0]
        sys.exit(1)
    # output record to screen
    vms_lib.put_output (rab.RBF)

# disconnect record stream
status = vms_sys.disconnect (rab)
if (status != RMS__NORMAL):
    print vms_sys.getmsg (rab.L_STS)[0]
    if (rab.L_STV != 0):
        print vms_sys.getmsg (rab.L_STV)[0]
    sys.exit (1)

# close file
status = vms_sys.close (fab)
if (status != RMS__NORMAL):
    print vms_sys.getmsg (rab.L_STS)[0]
    if (rab.L_STV != 0):
        print vms_sys.getmsg (rab.L_STV)[0]

# end
sys.exit(1)

# -----
#%$


(go to: table of contents, index)

11-JUN-2000 ZE.