Sha256: bd75a3067115a1593a6d368581c68784d6663df307fe70589fd255467d85f0b0
Contents?: true
Size: 1.59 KB
Versions: 42
Compression:
Stored size: 1.59 KB
Contents
class StandardError def exit_status return -1 end end module SctCore class SctPtyError < StandardError attr_reader :exit_status def initialize(e, exit_status) super(e) set_backtrace(e.backtrace) if e @exit_status = exit_status end end class SctPty def self.spawn(command) require 'pty' PTY.spawn(command) do |command_stdout, command_stdin, pid| begin yield(command_stdout, command_stdin, pid) rescue Errno::EIO # Exception ignored intentionally. # https://stackoverflow.com/questions/10238298/ruby-on-linux-pty-goes-away-without-eof-raises-errnoeio # This is expected on some linux systems, that indicates that the subcommand finished # and we kept trying to read, ignore it ensure begin Process.wait(pid) rescue Errno::ECHILD, PTY::ChildExited # The process might have exited. end end end $?.exitstatus rescue LoadError require 'open3' Open3.popen2e(command) do |command_stdin, command_stdout, p| # note the inversion yield(command_stdout, command_stdin, p.value.pid) command_stdin.close command_stdout.close p.value.exitstatus end rescue StandardError => e # Wrapping any error in SctPtyError to allow # callers to see and use $?.exitstatus that # would usually get returned raise SctPtyError.new(e, $?.exitstatus) end end end
Version data entries
42 entries across 42 versions & 1 rubygems