我目前正在编写一个CGI脚本,其最终目标是运行一个java程序,然后重定向到不同的页面。但是,当我尝试运行java程序时,CGI会导致500内部服务器错误。我尝试过os.system(“[command]”)和call([“command”])和subprocess.Popen(“command”),所有这三个问题都会导致同样的问题出现。任何建议,非常感谢。内部服务器错误 - Python CGI
编辑此外,Apache日志给我旁边没有信息说只有一个无效的头。
编辑
#!/usr/bin/python
# Import the CGI module
import cgi
import random
import os
import sys
import re
import subprocess
# Required header that tells the browser how to render the HTML.
print "Content-Type: text/html\n\n"
form = cgi.FieldStorage()
userID = random.random()
print "<html>"
print "<title>Results</title>"
print "<body>"
command = "java [classname] "
user_id = random.randint(0, sys.maxint)
command += str(user_id) + " "
command += re.sub(r'\s', '', form['key0'].value) + " "
command += form['key1'].value + " "
command += form['key2'].value + " "
command += form['key3'].value + " " if form.has_key('key3') else "0 "
## This is where the problem exists
#os.system("ls -l")
#call(["ls", "-l"])
#p = subprocess.Popen(command)
## End of Problem
print command
print "<br>"
print "Redirecting..."
print "<meta http-equiv='refresh' content='0;url=",
print "http://192.168.1.41/Path/",
print user_id,
print ".html' />"
print "</body>"
print "</html>"
整个命令是不存在的,但我相信这是正确建立,因为我可以复制打印命令并在终端上运行它,它运行完美。该命令只是简单的java [classname] [9 args]
java代码可以在Python代码之外流畅运行,它所做的只是生成一个.png文件和一个包含.png的.html文件。该文件的名称是[user_id] .html,因此是重定向。
内部服务器错误确实不是如果只有进程命令被注释掉,则会发生。
编辑最终放弃并转移到php来执行此脚本。感谢所有的帮助!
你可以发布你的代码吗?看起来像你的代码有错误,或者你的代码不会首先生成http头文件。 – YOU 2011-03-28 08:37:00
只有一些。我会尽我所能。 – mrK 2011-03-28 08:42:53