• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help with setting up Tomcat 6.018 for Python scripts

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry if my post is about Python, but not a lot of Python ppl run on Tomcat and I also develop in Java and was hoping perhaps some Java/Tomcat ppl could help me out.

I have done the following per the instructions from the Tomcat 6 CGI How-To (http://tomcat.apache.org/tomcat-6.0-doc/cgi-howto.html):
1) Added these lines in my web app's web.xml file:
<servlet>
<servlet-name>cgi</servlet-name>
<servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>cgiPathPrefix</param-name>
<param-value>WEB-INF/cgi</param-value>
</init-param>
<init-param>
<param-name>executable</param-name>
<param-value>d:\_python26\python.exe</param-value> <----- This is where I have Python installed
</init-param>
<load-on-startup>5</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>cgi</servlet-name>
<url-pattern>/cgi-bin/*</url-pattern>
</servlet-mapping>

2) In my web app's context.xml file I added privileged="true"

3) I saved this Python script (hello.py) below in "d:\_tomcat\webapps\python\WEB-INF\cgi" folder:
from os import *
from cgi import *

print "Content-type: text/html\n\n"
print "<B>Hello World!</B>"

4) Then I pointed my browser to "http://localhost/python/cgi-bin/hello.py" But all I get is a blank HTML page, no error messages at all. To see if it is because it is not finding my executable correctly, I removed the executable parameter, then I get a Perl not found error. I also used forward slashes and back slashes and I still get a blank page.

Let me preface this by saying my overall Tomcat installation is working correctly, my Java web apps work correctly. But for some reason, Tomcat is not parsing the .py file correctly or not at all. I also added the location of the python.exe to my OS's path variable (I'm on WinXP machine). But I still get the blank HTML page. Offline, my normal Python scripts run correctly also in interactive/command prompt mode.

I also tried adding "#!d:/_python26/python" or ""#!d:/_python26/python.exe" at the top of my Python script, but I still get a blank page (also tried back slashes too).

Any help on this would be greatly apprciated!

Regards,
Daniel
 
Dan Kim
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Eureka! I found what the problem was. For some reason, my environment variables weren't being passed correctly. So I added the following lines to my web.xml file to "force" the environment variables to be passed. Now my CGI scripts work!

<init-param>
<param-name>passShellEnvironment</param-name>
<param-value>true</param-value>
</init-param>

Errr, the Tomcat documentation is really lacking!


Dan Kim wrote:Sorry if my post is about Python, but not a lot of Python ppl run on Tomcat and I also develop in Java and was hoping perhaps some Java/Tomcat ppl could help me out.

I have done the following per the instructions from the Tomcat 6 CGI How-To (http://tomcat.apache.org/tomcat-6.0-doc/cgi-howto.html):
1) Added these lines in my web app's web.xml file:
<servlet>
<servlet-name>cgi</servlet-name>
<servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>cgiPathPrefix</param-name>
<param-value>WEB-INF/cgi</param-value>
</init-param>
<init-param>
<param-name>executable</param-name>
<param-value>d:\_python26\python.exe</param-value> <----- This is where I have Python installed
</init-param>
<load-on-startup>5</load-on-startup>
</servlet>

 
Dan Kim
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could someone tell me what specific relevance or ramifications are there if the passShellEnvironment is not set to true? I just want to know the details about this variable and why I did not get any indication that this was the root cause of my problem. I would expect to get some kind of feedback or indication other than a blank HTML page, but as stated previously, I did not get any error messages. I looked to see if other log files are being generated besides the usual standard log4j output, but could not find any others. Thanks in advance!

-Daniel
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic