Hi Fred,
// I haven't seen any documentation on how to add CGI capability to Zope.
// Before I spend my time writing a product or external method that allows
// me to call CGI programs from inside Zope, has anyone else already done
// this?
I have a C++ program I run from Zope and then return the results to Zope.
Just like you described, I farm the work out to an external method which
runs the CGI, grabs the results and hands them back to Zope.  Be sure to
hard code the line that calls your CGI.  Otherwise, the External Method
could be used to call any (potentially damaging) code on your Linux box.

The (simplified) DTML Method "displayResults":
<dtml-var standard_html_header>
<dtml-let ws=CWebCGI>  <- This creates and initializes an object with the
External Method
    <p>The initial gas heating usage: <dtml-var
    <p>The simulation method is invoked: <dtml-call "ws.simulate()"></p>
<- This invokes the Simulate method of the ws object, which is what calls
the CGI
    <p>The gas heating usage after the simulation: <dtml-var
"ws.calc.results.interestingValue"></p> <- this displays the results of the
CGI call
<dtml-var standard_html_footer>

The (simplified) External Method "CWebCGI":
import sys, os, string

class CResults:
        "Container for results"
        def __init__(self):
                self.interestingValue = 0.0

class CCalc:
        "Container for calculation data"
        def __init__(self):
                self.results = CResults()
                self.parameters = "enter your CGI's parameter(s) here (if any)"    #
Note this file is on the Linux Hard Drive, not the ZODB

class CWebCGI:
        "Container for the simulation"
        def __init__(self):
                self.calc = CCalc()
                self.execPath = "/path/to/the/CGIprogram"    # Note this file is on
the Linux Hard Drive, not the ZODB.

        def simulate(self):
                f = os.popen(self.execPath + " " + self.calc.parameters)
                lines = f.readlines()  # grab the output of the CGI here
                status = f.close()
                self.calc.results.interestingValue = string.split(lines[0], "=")[1]

def wsFactory():                        # <- This is the "Function Name" of the 
External Method
    return CWebCGI()

// Thanks for the bandwidth,
// Fred
Hope it helps,


Zope maillist  -  [EMAIL PROTECTED]
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-dev )

Reply via email to