User Tools

Site Tools


Please keep the examples in alphabetic order.

lib$cvt_from_internal_time, lib$convert_date_time, lib$free_date_time_context

from vms.rtl.lib import (convert_date_string, free_date_time_context,
from vms.libdtdef import LIB_K_DAY_OF_YEAR
# Convert our ASCII formatted date/time to VMS internal time format
s, dt, ctxt, defflt = convert_date_string('13-JAN-1993 14:54:09.24')
s, ctxt = free_date_time_context(ctxt)
# Add 1 day, VMS clock resolution is 100ns
dt += 10000000L * 3600 * 24
s, day = cvt_from_internal_time(LIB_K_DAY_OF_YEAR, dt)
print 'The day after 13-JAN is the %d day of the year 1993' % (day,)
s, day = cvt_from_internal_time(LIB_K_DAY_OF_YEAR)
print 'We are the %d day of the year' % (day,)

lib$cvt_vectim, lib$sys_asctim

from vms.rtl.lib import cvt_vectim, sys_asctim
# Convert '13-JAN-1993 14:54:09.24' to a binary representation
s, resultant_time  = cvt_vectim((1993, 1, 13, 14, 54, 9, 24))
# Convert the binary representation to the string one
s, resultant_string = sys_asctim(resultant_time)
print 'The text representation is:', resultant_string

lib$delete_logical, lib$get_logical, lib$set_logical

from vms.rtl.lib import delete_logical, get_logical, set_logical
from vms.ssdef import SS__SUPERSEDE
# Set the logical MY_LOGICAL to MY_VALUE in table LNM$JOB
s = set_logical('MY_LOGICAL', 'MY_VALUE', 'LNM$JOB')
if s == SS__SUPERSEDE:
    print 'The previous definition of the logical name was replaced.'
# Retreive the value of the previously defined logical
s, resultant_string, max_index = get_logical('MY_LOGICAL', 'LNM$JOB')
print 'Logical MY_LOGICAL was translated into', resultant_string
# Delete the previously defined logical
s = delete_logical('MY_LOGICAL', 'LNM$JOB')

lib$delete_symbol, lib$get_symbol, lib$set_symbol

from vms.rtl.lib import delete_symbol, get_symbol, set_symbol
from vms.libclidef import LIB_K_CLI_LOCAL_SYM, LIB_K_CLI_GLOBAL_SYM
# Set the local symbol MY_SYMBOL to MY_VALUE
s = set_symbol('MY_SYMBOL', 'MY_VALUE', LIB_K_CLI_LOCAL_SYM)
# Retreive the value of the previously defined symbol
s, resultant_string, table_type_indicator = get_symbol('MY_SYMBOL')
libtbl = {LIB_K_CLI_LOCAL_SYM : 'Local', LIB_K_CLI_GLOBAL_SYM : 'Global'}
print '%s Symbol MY_SYMBOL was translated into %s ' % (
# Delete the previously defined symbol
s = delete_symbol('MY_SYMBOL', LIB_K_CLI_LOCAL_SYM)


from vms.rtl.lib import do_command
# This will normally stop the program and execute the command supply
# If successful (the call to do_command, not the called command...)
# it does not return control to the calling program.
do_command('SHOW USERS')


from vms.rms import getrmsattr, RMSATTR_K_FID
from vms.rtl.lib import fid_to_name
fid = getrmsattr('sys$', RMSATTR_K_FID)
print 'The file ID of sys$ is', fid
fn = fid_to_name('sys$login',fid)[1]
print 'The file name for this file ID is', fn

lib$get_accnam, lib$format_sogw_prot, lib$parse_access_code, lib$parse_sogw_prot

from vms.rtl.lib import (format_sogw_prot, get_accnam, parse_access_code,
# Get the access name table for the FILE object class
accnam = get_accnam('FILE')[1]
print accnam
# Translate a string of access names into a mask for a each ownership category.
ownership_system = 0x000F
ownership_owner = 0x00F0
ownership_group = 0x0F00
ownership_world = 0xF000
system_access = parse_access_code("RWED", ownership_system, accnam)[1]
owner_acces = parse_access_code("REW", ownership_owner, accnam)[1]
group_access = parse_access_code("RE", ownership_group)[1]
world_access = parse_access_code("", ownership_world)[1]
access = system_access + owner_acces + group_access + world_access
# The mask has bits set for the access requested for the specified
# ownership category.
# This is opposite the standard protection format where a set
# bit in the protection mask means no access.
protection_mask = ~access & 0xFFFF
# Translate the protection mask into a protection string
print 'Protection string: "%s"' % (format_sogw_prot(protection_mask,
# Parse and translate the protection string into a protection mask
s, protection_mask, ownership_mask, end_position = \
# Translate the protection mask into a protection string
print 'Protection string: "%s"' % (format_sogw_prot(protection_mask,

lib$get_common, lib$put_common

from vms.rtl.lib import get_common, put_common
# Get the string in the common area.
s, resultant_string = get_common()
print 'Common area contains: "%s"' % resultant_string
# Copy the contents of a string into the common area.
s, resultant_length = put_common('My string')
print resultant_length, 'characters have been copied to the common area'


from vms.rtl.lib import getdvi
# get the full device namme (node name and device name)
devnam = getdvi(DVI__FULLDEVNAM, device_name=disk)[2]
# get the logical name of the volume
logvolnam = getdvi(DVI__LOGVOLNAM, device_name=disk)[2]
# get the number of free blocks on the disk
freeblocks = getdvi(DVI__FREEBLOCKS, device_name=disk)[1]
# print results
print 'disk %s:\n\tlogical name %s\n\t%d free blocks' % (devnam, logvolnam, freeblocks)
=== lib$get_ef, lib$free_ef ===
<code python>
from vms.rtl.lib import get_ef, free_ef
# Get an event flag
s, efn = get_ef()
print "Got event flag %u" % efn
# Free the event flag previously gotten.


from vms.rtl.lib import get_input
from vms.rmsdef import RMS__EOF
    s, input = get_input('Enter your input: ')
except VMSError, e:
    if e.errno == RMS__EOF:
        # CTRL-Z generate an eof which raise this error
        print 'CTRL-Z used'
        # Any other error is raised again and terminate the program
    print 'You have entered: "%s"' % input
vmsrtlexample.txt · Last modified: 2014/09/16 14:44 by wikiadmin