I have a ruby script that issues cap commands in bulk. What I would
like to do is to filter the output of that script to show only the
lines returned from the executing cap command that begin with a
certain number of ** before them. Basically rolling my own verbosity/
filter for cap in my script. I am admittedly weak in dealing with IO
in ruby and would love some help. I would like my interface to be
something like this.
filtered_out do
system(command)
end
The command would be the cap command of course and the filtered_out
method would capture the $stdout in some way and filter it to my
liking. My difficulty is thinking about how to do this in a way that
filters $stdout in realtime as it is being captured vs waiting for the
command to complete and then rewinding $stdout and filtering it
accordingly. While googling around, I found this neat method in
ZenTest and put it below to consideration, perhaps I can retool this?
# Captures $stdout and $stderr to StringIO objects and returns them.
# Restores $stdout and $stderr when done.
#
# Usage:
# def test_puts
# out, err = capture do
# puts 'hi'
# STDERR.puts 'bye!'
# end
# assert_equal "hi\n", out.string
# assert_equal "bye!\n", err.string
# end
def util_capture
require 'stringio'
orig_stdout = $stdout.dup
orig_stderr = $stderr.dup
captured_stdout = StringIO.new
captured_stderr = StringIO.new
$stdout = captured_stdout
$stderr = captured_stderr
yield
captured_stdout.rewind
captured_stderr.rewind
return captured_stdout, captured_stderr
ensure
$stdout = orig_stdout
$stderr = orig_stderr
end
--~--~---------~--~----~------------~-------~--~----~
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/capistrano
-~----------~----~----~----~------~----~------~--~---