Top Level Namespace
Defined Under Namespace
Modules: Klipp, Template Classes: String, StringInquirer
Instance Method Summary collapse
Instance Method Details
#capture_stdout ⇒ Object
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/klipp.rb', line 196 def capture_stdout old_stdout = STDOUT.clone pipe_r, pipe_w = IO.pipe pipe_r.sync = true output = '' reader = Thread.new do begin loop do output << pipe_r.readpartial(1024) end rescue EOFError end end STDOUT.reopen pipe_w yield ensure STDOUT.reopen old_stdout pipe_w.close reader.join return output end |