以下は努力の記録
#!/bin/sh exec 2>&1 ruby -Ke -S -x $0 "$@" | ruby -e 'require "cgi";((a=$stdin.read) !~ /^content/i)?(puts "content-type: text/html\n\n<h1>ERROR</h1><pre>#{CGI::escapeHTML("#{a}")}</pre>"):(print a)' #! ruby
#!/bin/sh exec 2>&1 ruby -Ke -S -x $0 "$@" | ruby -e 'require "cgi";(gets !~ /^content/i)?(puts "content-type: text/html\n\n<h1>ERROR</h1><pre>>#{CGI::escapeHTML("#{$_}#{$stdin.read}")}</pre>"):(print $_,$stdin.read)' #! ruby
#!/bin/sh exec 2>&1 ruby -Ke -S -x $0 "$@" | ./error.rb #! ruby puts '
パスの通った所に以下を error.rbとして保存する
#!/usr/bin/ruby require 'cgi' if gets !~ /content-type/i print <<EOS content-type: text/html <h1>ERROR</h1> <pre>#{CGI::escapeHTML($_)}#{CGI::escapeHTML($stdin.read)}</pre> EOS else print $_,$stdin.read end
-Sオプションを使って まずhtmlヘッダを出力し、標準エラーを標準入力へリダイレクトした後スクリプトを実行する
#!/bin/sh echo "content-type: text/html" echo exec 2>&1 ruby -S -x $0 "$@" #! ruby begin puts <<-EOS aaaaa EOS end
こんなの考えてみたけどヘッダがこんなに長いのは気持ち悪くなってきたので却下。
!/bin/sh echo "content-type: text/html" echo export a=`uuidgen` command ruby -S -x $0 "$@" >& /tmp/$a echo $a if [ -e /tmp/$a ]; then cat /tmp/$a| sed 's/$/<br>/g' rm /tmp/$a fi exit end #! ruby begin ret=0 10.times{|i| ret+=i} require 'kakasi' puts <<-EOS aaaaa EOS end