User Tools

Site Tools


vmsptdexample

example 1

#!python
from vms.starlet.ptdlib import Ptd
# create a pseudo terminal with the default prompt "pseudo_term> "
ptd = Ptd()
# read all lines until prompt
lines = ptd.read_until_prompt()
# print all read lines
for line in lines:
    print line,
# execute the DCL command "show system"
e,lines = ptd.execute('show system')
# print the result
print e,
for line in lines:
    print line,

example 2

#!python
from vms.starlet.ptdlib import Ptd
 
def execute(ptd, cmd):
    e,lines = ptd.execute(cmd)
    print e,
    for line in lines:
        print line,
 
ptd = Ptd()
lines = ptd.read_until_prompt()
for line in lines:
    print line,
 
execute(ptd, 'set terminal/device=vt200')
execute(ptd, 'show terminal')
execute(ptd, 'show default')
execute(ptd, 'show symbol $status')
}}}
 
=== example 3 ===
 
<file python>
#!python
import time
from vms.starlet.ptdlib import Ptd, KEYS
from vms.ssdef import SS__TIMEOUT
 
fo = open("trace.log", "w")
def execute_until(ptd, cmd, maxtime):
    endtime = time.time() + maxtime
    s = ptd.writeln(cmd)
    print >>fo, repr(s)
    try:
        while(True):
            curtime = time.time()
            timeout = int(endtime - curtime)
            if timeout <= 0:
                break
            s = ptd.read(timeout)
            print >>fo, repr(s)
    except VMSError, e:
        return
 
def execute(ptd, cmd):
    e,lines = ptd.execute(cmd)
    print >>fo, repr(e)
    for line in lines:
        print >>fo, repr(line)
 
ptd = Ptd()
lines = ptd.read_until_prompt()
for line in lines:
    print >>fo, repr(line)
 
execute(ptd, 'set terminal/dev=vt200')
 
execute(ptd, 'show terminal')
 
execute_until(ptd, 'rmu/sh stat mf_personnel', 15)
print >>fo, '-' * 50
for line in ptd.screen():
    print >>fo, line
print >>fo, '-' * 50
 
ptd.write('E')
lines = ptd.read_until_prompt()
for line in lines:
    print >>fo, repr(line)
 
 
execute_until(ptd, 'monitor system/all', 15)
print >>fo, '-' * 50
for line in ptd.screen():
    print >>fo, line
print >>fo, '-' * 50
 
ptd.write(KEYS['CTRL-Z'])
lines = ptd.read_until_prompt()
for line in lines:
    print >>fo, repr(line)

example 4

#!python
from vms.starlet.ptdlib import Ptd
 
ptd = Ptd()
ptd.read_until_prompt()
 
print ptd.writeln('show system'),
print ptd.read_until([' CUR ', ptd.prompt])[3][-1]

example 5

#!python
import time
from vms.starlet import ptdlib
from vms.ssdef import SS__TIMEOUT
 
fo = open("trace.log", "w")
def execute_until(ptd, cmd, maxtime):
    endtime = time.time() + maxtime
    s = ptd.writeln(cmd)
    print s,
    print >>fo, repr(s)
    try:
        while(True):
            curtime = time.time()
            timeout = int(endtime - curtime)
            if timeout <= 0:
                break
            s = ptd.read(timeout)
            print s,
            print >>fo, repr(s)
    except VMSError, e:
        return
 
def execute(ptd, cmd):
    e,lines = ptd.execute(cmd)
    print e,
    print >>fo, repr(e)
    for line in lines:
        print line,
        print >>fo, repr(line)
 
ptd = ptdlib.Ptd()
lines = ptd.read_until_prompt()
for line in lines:
    print line,
    print >>fo, repr(line)
 
execute(ptd, 'set terminal/dev=vt100/pag=24/widt=80')
 
execute(ptd, 'show terminal')
 
execute_until(ptd, 'edit', 5)
ptd.write('toto')
ptd.write(ptdlib.KEYS["DO"])
ptd.writeln('quit')
ptd.writeln('')
lines = ptd.read_until_prompt()
for line in lines:
    print line,
    print >>fo, repr(line)
 
execute(ptd, 'set terminal/dev=vt100/pag=24/widt=80')
 
execute(ptd, 'show terminal')
 
execute_until(ptd, 'edit', 5)
ptd.write('toto')
ptd.write(ptdlib.KEYS["DO"])
ptd.writeln('quit')
ptd.writeln('')
lines = ptd.read_until_prompt()
for line in lines:
    print line,
    print >>fo, repr(line)
vmsptdexample.txt · Last modified: 2014/09/16 15:26 by wikiadmin