On 17 Jul 2001 19:55:19 +0900, Steve Hill wrote: > Hi, > I'm sure this isn't really a ruby specific question, but since I scipt > in ruby, maybe someone has a good answer... > > Some of the scripting relies on some of the standard unix tools to do > its work, called using backquotes. e.g. the following facet which > processes the columns of a file previously created with grep. > > `grep FOO foo.txt > foo.tmp` > > flag?=false > hash=Hash.new > IO.for_each("foo.tmp") do |line| > unless flag? do > cols=line.split > (0...cols).each {|i| hash[i]=Bar.new} > end > > cols=line.split > hash.each {|k,v| v.process(cols[i]) } #A > end > > The problem is that the script may fail at the line marked A because > the file "foo.tmp" has either not been written at all, or has not been > completely written. > > The first problem can be solved by inserting the following section > after the grep. > > while !File.stat?("foo.tmp").size? > sleep 0.001 > end > > Does anyone know how to test that "foo.tmp" has been completely > written? > Don't write to a file. Write to the program instead. Something like this I think: IO.popen("grep FOO foo.txt").each do |line| # do stuff with |line| end -- Erik BéČfors | http://erik.bagfors.nu/ erik / bagfors.nu | Erik.Bagfors / ardendo.se Supporter of free software | GSM +46 733 279 273 fingerprint: 6666 A85B 95D3 D26B 296B 6C60 4F32 2C0B 693D 6E32