From: Dave Thomas Date: 2001-07-17T22:04:45+09:00 Subject: [ruby-talk:17997] Re: waiting for `backquotes` to finish stephen.hill@motorola.com (Steve Hill) writes: > 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. ... > 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. This shouldn't be a problem, because the command in backquotes will run to completion _before_ the rest of your code is executed. However, there's a way to bypass this altogether: you can run the underlying command and have your Ruby program read the output directly, rather than having to write the output to a file and subsequently opening the file. Try: IO.popen("grep FOO foo.txt") do |pipe| pipe.each do |line| # ... end end A couple of other points. In your original code chunk, you had 'flag? = false'. Does that compile in your version of Ruby? You also had unless flag? do ... end Although this looks reasonable, it isn't what you meant. The 'do' introduces a block (as in an iterator block), not the body of a compound statement. This will force 'flag?' to be interpreted as a method name. Dave