class U3dCore::SafePty
Executes commands using PTY and takes care of error handling and more
Public Class Methods
spawn(command) { |r, w, p| ... }
click to toggle source
Wraps the PTY.spawn() call, wait until the process completes. Also catch exceptions that might be raised See also www.omniref.com/ruby/gems/shell_test/0.5.0/files/lib/shell_test/shell_methods/utils.rb
# File lib/u3d_core/command_runner.rb, line 55 def self.spawn(command, &_block) require 'pty' PTY.spawn(command) do |r, w, p| begin trap('INT') do Process.kill("INT", p) end yield r, w, p # if the process has closed, ruby might raise an exception if we try # to do I/O on a closed stream. This behavior is platform specific # rubocop:disable HandleExceptions rescue Errno::EIO # rubocop:enable HandleExceptions ensure begin Process.wait p # The process might have exited. # This behavior is also ruby version dependent. # rubocop:disable HandleExceptions rescue Errno::ECHILD, PTY::ChildExited end # rubocop:enable HandleExceptions end end $CHILD_STATUS.exitstatus end