Module: IO::Tee
- Defined in:
- lib/io/tee/version.rb,
lib/io/tee.rb
Constant Summary collapse
- VERSION =
"1.0.0"
Instance Method Summary collapse
Instance Method Details
#tee(filename, append: true) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/io/tee.rb', line 4 def tee(filename, append: true) append_argument = append ? '--append' : '' tee_cmd = "tee #{append_argument} #{filename}" tee_output, tee_input = IO.pipe tee_pid = Process.spawn tee_cmd, in: tee_output, out: self reopen(tee_input) at_exit do sleep 0.05 # see doc/why-sleep.md Process.kill('TERM', tee_pid) Process.waitpid(tee_pid) end end |