cgiはじめ

エスケープを覚えた!
はじめはまぁこうなるわな

#! /usr/bin/env ruby
require 'cgi'
#htmlエスケープを覚えたのでgoogleサーチに流すというとても短絡的な犯行
#google searchのアドレス"支払拒絶証書"の例
#http://www.google.co.jp/search?q=%E6%94%AF%E6%89%95%E3%81%84%E6%8B%92%E7%B5%B6%E8%A8%BC%E6%9B%B

#検索ワード
str = "example searchword" #default
#コマンド
command = "C:/Program Files/Mozilla Firefox/firefox.exe "
#ARGVパース
if ARGV == []
	puts "usage: gsearch.rb <searchword>"
        puts "and now,we test seach with 'example seachword'"
else
	str = ""
	ARGV.each do |t|
		str << "#{t} "
        end
end

#エスケープ
estr = CGI.escape(str)
#検索クエリURI生成
urig = "http://www.google.co.jp/search?q=" + estr 
system("#{command} #{urig}")

exerbでexe化してwinディレクトリとかにgs.exeとかでほりこんでおけば