User Tools

Site Tools


vmsptdexample

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

vmsptdexample [2014/09/16 15:26] (current)
wikiadmin created
Line 1: Line 1:
 +=== example 1 ===
 +
 +<file python>
 +#!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,
 +</​file>​
 +
 +=== example 2 ===
 +
 +<file python>
 +#!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)
 +
 +</​file>​
 +
 +
 +=== example 4 ===
 +
 +<file python>
 +#!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]
 +</​file>​
 +
 +=== example 5 ===
 +
 +<file python>
 +#!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)
 +</​file>​
  
vmsptdexample.txt ยท Last modified: 2014/09/16 15:26 by wikiadmin