class RETerm::Components::CmdOutput
Run command, capture and display output
Public Class Methods
new(args={})
click to toggle source
Initialize the CmdOutput
component
@param [Hash] args cmd output params @option args [String] :cmd command to run
Calls superclass method
# File lib/reterm/components/cmd_output.rb, line 12 def initialize(args={}) activate_sync! super @cmd = args[:cmd] end
Public Instance Methods
finalize!()
click to toggle source
# File lib/reterm/components/cmd_output.rb, line 32 def finalize! if running? Process.kill @pid @stdout.close @stdout.close end end
running?()
click to toggle source
# File lib/reterm/components/cmd_output.rb, line 19 def running? !!@pid && process_alive?(@pid) end
start!()
click to toggle source
# File lib/reterm/components/cmd_output.rb, line 40 def start! @stdout, @stdin, @pid = PTY.spawn(@cmd) self end
sync!()
click to toggle source
# File lib/reterm/components/cmd_output.rb, line 23 def sync! out = nil begin out = @stdout.gets rescue Errno::EIO end self << out if out end
wait()
click to toggle source
# File lib/reterm/components/cmd_output.rb, line 45 def wait while running? begin Timeout.timeout(SYNC_TIMEOUT.to_f/1000) do begin Process.waitpid @pid rescue # rescue needed incase process exit between # running? check and waitpid end end rescue Timeout::Error run_sync! end end # NOTE: at this point process will be closed but # there may still be unread data in stdout/stderr # buffers!!! self end