私は現在、Java プログラムを実行してから別のページにリダイレクトするという最終目標を持つ CGI スクリプトを作成しています。ただし、Java プログラムを実行しようとすると、CGI によって 500 内部サーバー エラーが発生します。os.system("[command]") と call(["command"]) と subprocess.Popen("command") を試しましたが、3 つすべてで同じ問題が発生します。どんな提案でも大歓迎です。
編集また、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 であるため、リダイレクトされます。
プロセス コマンドのみがコメント アウトされている場合、内部サーバー エラーは発生しません。
EDITこのスクリプトを実行するためにあきらめてphpに移動することになりました。助けてくれてありがとう!