14th Fri
Rubyから外部プログラムを呼び出す方法
Rubyから外部プログラムを呼び出して、
パイプを使ったプロセス間通信をする方法の紹介です。
Rubyから外部のプログラムを起動して、標準入力からデータを入力し、
標準出力から結果を取り出したいという場合には、IO.popenを使うと便利です。使い方は以下のとおり。
ruby>>
IO.popen('/usr/bin/command', 'r+') do |io|
io.puts "something to input"
@result = io.gets
end
<<ruby
See Also
posted by
genki on Fri 14 Mar 2008 at 18:39 with 0 comments