def capture_stdout
    if ENV['DEBUG'] # Skip if debug mode
      yield
      return ""
    end

    out = StringIO.new
    $stdout = out
    $stderr = out
    yield
    return out.string
  ensure
    $stdout = STDOUT
    $stderr = STDERR
  end
Redirect standard out, standard error and the buffered logger for sprinkle to StringIO
capture_stdout { any_commands; you_want } => "all output from the commands"