#!/usr/bin/env ruby # coding: utf-8 Encoding.default_external = 'utf-8' require'cgi' require'open3' require'timeout' c = CGI.new(:accept_charset => "UTF-8") code = "for i in 1..1000 puts(\"baka\") end" cmd = "ruby -Ku -e '#{code}'" o,e,s = Open3.capture3(cmd) print <<EOF Content-type: text/html; charset=utf-8 <!DOCTYPE html> <html> <head> <meta charset=utf-8> <title>テキストエディタ読込</title> <link rel="stylesheet" type="text/css" href="root/editor.css"> <style> </style> </head> <body> <form method="POST" action="./textcode.rb"> <h3>名前を入力してください</h3> <input type="text" name="name"></input> <h1>1〜1000までの数を表示させるプログラムを作成してください。</h1> <textarea name="example">プログラムのコードを入力</textarea> <input type="submit" value="Let Go"> <input type="reset" value="reset"> <h2>出力例</h2> <p id="kome">※print文などで一文づつ書いている場合は減点しまーーーーす</p> EOF puts("<div>") printf("<textarea id=\"black\" name=\"ans\">%s</textarea>\n", o) puts("</div>") puts("</form>") puts("</body>\n</html>")