Class: U3dCore::SafePty
- Inherits:
-
Object
- Object
- U3dCore::SafePty
- Defined in:
- lib/u3d_core/command_runner.rb
Overview
Executes commands using PTY and takes care of error handling and more
Class Method Summary collapse
-
.spawn(command, &_block) ⇒ Object
Wraps the PTY.spawn() call, wait until the process completes.
Class Method Details
.spawn(command, &_block) ⇒ Object
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
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# 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 |