# File lib/background_process/pty_background_process.rb, line 14 def self.run(command) thread = Thread.new do # why run PTY separate thread? When a PTY instance # dies, it raises PTY::ChildExited on the thread that # spawned it, interrupting whatever happens to be # running at the time PTY.spawn(command) do |output, input, pid| begin bp = new(pid, input, output) Thread.current[:background_process] = bp bp.wait rescue Exception => e puts e puts e.backtrace end end end sleep 0.01 until thread[:background_process] thread[:background_process] end