I have written a script which sets up a new website on a server.
Obviously this involves a number of steps so I have written a method
which looks like so:
step(“Creating site directory”) { [mkdir code here }
This all works fine, except for one thing. I would like the “Creating
site directory…” to show up before the yield takes place, and then
the “done” would appear afterwards. Currently the whole “Creating site
directory… done” appears only after the yield has completed, which
might make the user think something has gone wrong with longer steps. I
don’t understand why this happens, can anyone explain my options please?
Thanks, that works a treat. Now, another related question. Part of the
process involves checking the code out from Subversion. As Subversion
checks out, it writes lines to STDOUT saying what it is downloading. I
would like this to be outputted by by script in real time, rather than
when the whole command has finished running. Currently I am using a
method like this:
def command(command)
open("|#{command}", “r”) do |f|
f.each do |line|
puts line
STDOUT.flush
end
end
end
However, that doesn’t seem to work. The output still only comes when the
command has fully completed. Any ideas of what I can do?