This shows you the differences between two versions of the page.
— |
rubypopenex [2014/10/25 21:52] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ==== Ruby popen example ==== | ||
+ | <code lang="ruby"> | ||
+ | # $Id$ | ||
+ | # | ||
+ | # /home/madann/learn/ruby/pope.rb | ||
+ | # | ||
+ | |||
+ | require 'getoptlong' | ||
+ | |||
+ | f = IO.popen(exec("tail -f mylog.log | grep -i error")) | ||
+ | while (1) do | ||
+ | trap("INT") { exit } | ||
+ | line = f.readline.chomp | ||
+ | puts "#{line};" if (line.include?("*ERROR*")) | ||
+ | end | ||
+ | f.close | ||
+ | |||
+ | </code> | ||
+ | |||
+ | ---- | ||
+ | * [[rubyinfo|Back to Ruby]] | ||