From: Jens Luedicke Date: 2001-04-22T04:30:12+09:00 Subject: [ruby-talk:13996] Re: regexp problem ... hi there ... I want to read from @io while the created thread is alive. t = Thread.fork() { @io = IO.popen("wget " + url + " 2>&1") } while t.alive? i = @io.readline if /(.)(\d+)(%]\n)/ =~ i @progressbar.setProgress($2.to_i) end end > ----- Original Message ----- > From: ts > To: ruby-talk@ruby-lang.org (ruby-talk ML) > Cc: ruby-talk@ruby-lang.org > Subject: [ruby-talk:13993] regexp problem ... > > >>>>> "J" == Jens Luedicke writes: > > J> io = IO.popen("wget --dot-style=micro " + url) > > First I need to redirect stderr on stdout, i.e. > > io = IO.popen("wget --dot-style=micro " + url + " 2>&1") > > J> out = io.readlines > > J> for i in out > J> print /(.)(\d+)(%]\n)/.match(i)[2], "\n" > > Best to write it like this > > if /(.)(\d+)(%]\n)/ =~ i > puts $2 > end > > > If the regexp don't match #match will return nil, and ruby will give an > error message (method [] not found for nil) > > > Guy Decoux -- with friendly regards.... jens luedicke http://www.irs-net.com/ - C8H10N4O2 -