Created: 05-Dec-1997 Updated: 25-Dec-1997
Site Index of Changed Web Pages

Python-to-REXX (PyREXX) Extension Module

The PyREXX module is an extension to Python that allows it to invoke functions within those DLLs that REXX can call. There are many such DLLs available, such shipped with products and some freeware. It is also an easy way for someone to wrap a programming interface and have it usable by both REXX and Python without having to learn the internals of Python.

I have pre-built the PyREXX module into the binaries on this web site, for ease of use, but the extension module (59KB) by itself with sources is available.

Known REXX DLLs

  Library and API Reference  Functionality

  \os2\dll\rexxutil.dll      System API and Some Workplace Shell Stuff
  \os2\books\rexx.inf        (Also Access to Extended Attributes on Files)

  \mmos2\dll\mciapi.dll      Multimedia API
  \mmos2\mcirexx.inf

  \tcpip\dll\rxftp.dll       TCP/IP FTP API
  \tcpip\help\rxftp.inf

  \tcpip\dll\rxsocket.dll    TCP/IP Sockets API
  \tcpip\help\rxsocket.inf

  \db2\sqllib\dll\db2ar.dll  IBM DB2/2 Database (SQL Commands)
  \db2\sqllib\book\*.inf
There are numerous other freeware DLLs available. (serial I/O, NetBIOS, Lan Server, POP3, etc.)

Simple Example

    import string
    from rexx import REXXModule, EnterREXX, rexxvar

    def main():
        rxutil = REXXModule('rexxutil')

        print "You are running OS/2 %s" % rxutil.SYSOS2VER()

        rxutil.SYSQUERYCLASSLIST('wpsclasses.')
        numclasses = string.atoi( rexxvar['wpsclasses.0'] )

        for i in range(numclasses):
            print rexxvar['wpsclasses.%d' % i]

    if __name__ == "__main__":
        EnterREXX(main)

Example of Python Accessing the REXX Multimedia DLL

    import string
    from rexx import REXXModule, EnterREXX, rexxvar

    class Audio:
        def __init__(self):
            self.mci = REXXModule('mciapi')
            rc = self.mci.mciRxInit()
            print "rc = %d" % string.atoi(rc)

        def __del__(self):
            self.mci.mciRxExit()

        def issueCmd(self, cmd):
            rc = self.mci.mciRxSendString(cmd, 'RetSt', '0', '0')
            rc = string.atoi(rc)
            if rc != 0:
                self.mci.mciRxGetErrorString(rc, 'ErrStVar')
                raise "AudioException", (rc, rexxvar['ErrStVar'])
            else:
                return rexxvar['RetSt']

    def main():
        aud = Audio()

        print "Open Gives '%s'" % aud.issueCmd('open test.wav alias pyalias wait')
        print "Play Gives '%s'" % aud.issueCmd('play pyalias wait')
        print "Close Gives '%s'" % aud.issueCmd('close pyalias wait')

    if __name__ == "__main__":
        EnterREXX(main)

Example of Stem Variable Usage re List of Processes Running

    import string
    from rexx import REXXModule, EnterREXX, rexxvar

    def main():
        rxydba = REXXModule('ydbautil')

        print "Using Version %s" % rxydba.RXYDBAUTILQUERY()[:33]

        x = rxydba.RXQPROCSTATUS("proc.")
        print "Invoking RxQProcStatus returns '%s'" % x

        print " PID PPID TYPE STAT SESS #T PRI MODULE"

        for procslot in range(1, string.atoi( rexxvar['proc.0P.0'] )+1 ):

            PID  = string.atoi( rexxvar[ 'proc.0P.%d.1'      % procslot ], 16 )
            PPID = string.atoi( rexxvar[ 'proc.0P.%d.2'      % procslot ], 16 )
            TYPE = string.atoi( rexxvar[ 'proc.0P.%d.3'      % procslot ]     )
            STAT = string.atoi( rexxvar[ 'proc.0P.%d.4'      % procslot ][:8] )
            SESS = string.atoi( rexxvar[ 'proc.0P.%d.5'      % procslot ]     )
            NUMT = string.atoi( rexxvar[ 'proc.0P.%d.0T.0'   % procslot ]     )
            PRI  =              rexxvar[ 'proc.0P.%d.0T.1.4' % procslot ][-3:]
            MOD  =              rexxvar[ 'proc.0P.%d.6'      % procslot ]

            try:
                TYPE = ('FSC', 'RMD', 'VIO', 'PMW', 'DET')[TYPE]
            except:
                TYPE = `TYPE`

            if NUMT == 0:
                PRI = " - "

            print string.rjust(`PID`,    4),\
                  string.rjust(`PPID`,   4),\
                  string.rjust(TYPE,     4),\
                  string.zfill(STAT,     4),\
                  string.zfill(SESS,     4),\
                  string.rjust(`NUMT`,   2),\
                  string.rjust(PRI ,   3),\
                  MOD

        print " "
        print "Legend:"
        print "  Task Type: FSC = Full-Screen, RMD = Realmode, DET = Detached"
        print "             VIO = Virtualized Char-Mode Screen, PMW = PM Window"

    if __name__ == "__main__":
        EnterREXX(main)

Pagemaster <jrush@summit-research.com>