Class: Spud::Shell

Inherits:
String
  • Object
show all
Defined in:
lib/shell.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cmd, silent: false) ⇒ Shell

Returns a new instance of Shell.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/shell.rb', line 7

def initialize(cmd, silent: false)
  @pid = nil
  @status = nil
  output = StringIO.new

  Open3.popen3(cmd) do |_, stdout, _, thread|
    @pid = thread.pid

    begin
      while line = stdout.gets
        puts line unless silent
        output.puts line
      end
    rescue Interrupt
      exit
    end
  end

  @status = $?
  puts status: @status
  super(output.string)
end

Instance Attribute Details

#statusObject

Returns the value of attribute status.



5
6
7
# File 'lib/shell.rb', line 5

def status
  @status
end

Instance Method Details

#kill!Object



30
31
32
# File 'lib/shell.rb', line 30

def kill!
  Process.kill('HUP', @pid)
end