Meaningless Drivel is fun!*
The moose likes Tomcat and the fly likes Help with setting up Tomcat 6.018 for Python scripts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Help with setting up Tomcat 6.018 for Python scripts" Watch "Help with setting up Tomcat 6.018 for Python scripts" New topic
Author

Help with setting up Tomcat 6.018 for Python scripts

Dan Kim
Greenhorn

Joined: Dec 17, 2005
Posts: 16
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

Joined: Dec 17, 2005
Posts: 16
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

Joined: Dec 17, 2005
Posts: 16
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Help with setting up Tomcat 6.018 for Python scripts
 
Similar Threads
unable to run webapplications in tomcat
Struts Application is not running
tomcat as service -> cannot start WINWORD.exe
Perl/Cgi in Tomcat 5.5
Multiple Struts-config.xml in Jboss 4.2.1