"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
Tres Seaver wrote:
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>
but be careful, since this is a security hole. the executed command line should be hardcoded. -- Itamar S.T. itamars@ibm.net
You know after reading this thread I was pretty surprised that we didn't have simply execcgi ability in Zope, considering how trivial it is. I'll look into something like this possibly being a feature. Thanks Tres! -Michel Tres Seaver wrote:
"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
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Michel Pelletier wrote:
You know after reading this thread I was pretty surprised that we didn't have simply execcgi ability in Zope, considering how trivial it is.
I'll look into something like this possibly being a feature.
Thanks Tres!
-Michel
Note that the version I posted has several rough edges: * It doesn't propagate the CGI environment to the child process. We could fix this on Unixen by doing a fork() and some execve() magic, but then we lose the convenience of popen(); CreateProces() on Win32 requires special handling, too. * It doesn't propagate the input stream some CGI's may expect to find. "Temp files and fork() and dup(), oh my!" * Win32 versions to use the win32.popen(), instead of os.popen(). * The error handling is ugly. * It double-buffers results (which could get ugly if the CGI does weird stuff, or returns a really huge result). In short, its a pretty ugly bandaid, recommended only for easing the CGI withdrawal jitters. :) Doing the Right Thing (TM) involves reimplementing a big chunk of a web server, which is probably why Zope Didn't Go There already. mod_rewrite looks pretty sane by comparison. Tres. -- ========================================================= Tres Seaver tseaver@palladion.com 713-523-6582 Palladion Software http://www.palladion.com
What an exellent deflation. ;) Tres Seaver wrote:
Michel Pelletier wrote:
You know after reading this thread I was pretty surprised that we didn't have simply execcgi ability in Zope, considering how trivial it is.
I'll look into something like this possibly being a feature.
Thanks Tres!
-Michel
Note that the version I posted has several rough edges:
* It doesn't propagate the CGI environment to the child process. We could fix this on Unixen by doing a fork() and some execve() magic, but then we lose the convenience of popen(); CreateProces() on Win32 requires special handling, too.
Environemt propagation after a fork wouldn't be too hard, and I was kindof assuming punting on Win32.
* The error handling is ugly.
There wouldn't need to be much, just catching errors from the Zope side code, anything the CGI raises is it's own problem.
* It double-buffers results (which could get ugly if the CGI does weird stuff, or returns a really huge result).
Yeah yer right there...
In short, its a pretty ugly bandaid, recommended only for easing the CGI withdrawal jitters. :) Doing the Right Thing (TM) involves reimplementing a big chunk of a web server, which is probably why Zope Didn't Go There already. mod_rewrite looks pretty sane by comparison.
Ok you sold me, I wasn't volunteering anyway (I said I'd *look* at it. ;). -Michel
participants (3)
-
Itamar Shtull-Trauring -
Michel Pelletier -
Tres Seaver