Class: Sh

Inherits:
Object
  • Object
show all
Defined in:
lib/command/sh/sh.rb

Overview

Run bash commands locally on machine.

Instance Method Summary collapse

Constructor Details

#initializeSh

Returns a new instance of Sh.



7
# File 'lib/command/sh/sh.rb', line 7

def initialize; end

Instance Method Details

#run(command) ⇒ Object

Run a bash command locally.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/command/sh/sh.rb', line 10

def run(command)
  output = ''
  exit_status = nil
  Open3.popen3(command) do |stdin, stdout, stderr, wait_thr|
    stdin.close
    stdout.each_line do |line|
      puts line
      output += line
    end
    stderr.each_line do |line|
      puts line
      output += line
    end
    exit_status = wait_thr.value
    return { output: output, result: exit_status.success? }
  end
end