Class: Maintainer::MaintainerPty

Inherits:
Object
  • Object
show all
Defined in:
lib/maintainer_core/commandRunner.rb

Class Method Summary collapse

Class Method Details

.spawn(command) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/maintainer_core/commandRunner.rb', line 18

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

    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
    puts "ERROR: #{e}"
raise MaintainerPtyError.new(e, $?.exitstatus)
end