#!/usr/bin/env ruby # coding: utf-8 Encoding.default_external = 'utf-8' require'kconv' require'cgi' require'open3' require'timeout' begin Timeout.timeout(0.5){ c = CGI.new(:accept_charset => "UTF-8") # question = c["que"] # pro = c["program"].toutf8 # mes = c["mes"] # hint = c["hint"] p = "puts\"aa\"" que = "問題文" mes = "メッセージ" cmd = "ruby -Ku -e '#{p}'" o,e,s = Open3.capture3(cmd) print("Content-type: text/html; charset=utf-8\n\n") print <<EOF <!DOCTYPE html> <html> <head> <meta charset=utf-8> <title>テキストエディタ読込</title> <link rel="stylesheet" type="text/css" href="editor.css"> <style> </style> </head> <body> <form method="POST" action="./textcode.rb"> <h3>名前を入力してください</h3> <input type="text" name="name"></input> EOF printf("<h1>%s</h1>\n", que) print <<EOF <textarea name="example">プログラムのコードを入力</textarea> <input type="submit" value="Let Go"> <input type="reset" value="reset"> <h2>出力例</h2> EOF printf("<textarea id=\"black\" name=\"ans\">%s</textarea>\n", o.toutf8) printf("<h1>どこでつかうの??</h1><p>%s</p>\n", mes) puts("</form>") puts("</body>\n</html>") } rescue Timeout::Error file = File.open("errormes.txt", "r") puts file.read file.close end