XREAでは#exec cmdが使えません。 よって、#exec cmdを使っている場合は#exec cgiにします。
大きな違いは三つほどです。 一つ目は、実行環境です。 二つ目は、httpヘッダの必要性。 三つ目は、cgiを検索するパス。
まずは、#exec cmdを#exec cgiに直します。 また、絶対パスで指定されている場合は相対パスにしてください。
実行するディレクトリに注意してください。 ssiのファイルと同じディレクトリに置く場合は問題ないですが、 違うディレクトリに置く場合は、違いがでてきます。 つまり、ファイルの検索が絶対ではなく相対パスの場合、 どこのディレクトリを機転とするかが代わってくるのです。
実際の例を見てみましょう。 ファイルは以下のように設置します。
/
└ public_html/
├ index.shtml
└ count/
├ count.cgi
└ data.txt
index.shtml
<html> <head><title>カウンタ</title></head> <body><p><!--#exec cmd="./count/count.cgi"-->番</p></body> </html>
count.cgi(Perl)*2
#!/usr/bin/perl
count.cgi(Ruby)
#!/usr/local/bin/ruby
count = nil
open("count/data.txt" "r+") do |file|
count = file.read.to_i
count += 1
file.rewind
file.truncate(0)
file.write(count.to_s)
end
print count
exit
index.shtml
<html> <head><title>カウンタ</title></head> <body><p><!--#exec cgi="./count/count.cgi"-->番</p></body> </html>
count.cgi(Perl)*3
#!/usr/bin/perl
count.cgi(Ruby)
#!/usr/local/bin/ruby
count = nil
open("data.txt" "r+") do |file| # データファイルのパスを変更
count = file.read.to_i
count += 1
file.rewind
file.truncate(0)
file.write(count.to_s)
end
print "Content-type: text/html\r\n\r\n" # httpのヘッダを書き込む
print count
exit