[Zope] newbie CGI question
Tres Seaver
tseaver@palladion.com
Wed, 22 Mar 2000 08:51:41 -0600
"Eric Walstad" <ewalstad@energywright.com>
>
> Hung Jung Lu ,
> Along these same lines, I have a C++ CGI App that I would like to call from
> zope. It requires a couple of parameters. The app can either return HTML
> or I can have it save the output to a text file. Ultimately, the text will
> need to be displayed to the user from Zope.
> Q1. How does one call a C++ CGI program from Zope?
> Q2. How do you supply the C++ CGI program with "command line" parameters
> from Zope when making the call?
From Python (either an ExternalMethod or a product)::
import sys, os, string
def ExecCGI( cmdLine ):
"""
Run an external command and return its standard output as a string.
"""
f = os.popen( cmdLine ) # note that Win32 has a non-standard popen()
lines = f.readlines()
status = f.close()
if status:
raise "CGI returned error: %d" % status[1]
return string.join( lines )
To call it from DTML, passing the current values of 'foo' and 'bar'::
<dtml-let cmdLine="'/path/to/my/cgi %s %s' % ( foo, bar )">
<dtml-var "ExecCGI( cmdLine )">
</dtml-let>
Tres.
--
=========================================================
Tres Seaver tseaver@palladion.com 713-523-6582
Palladion Software http://www.palladion.com