Class: WaveToJson::ShellCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/wave_to_json/shell_command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(commands) ⇒ ShellCommand

Returns a new instance of ShellCommand.



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

def initialize(commands)
  @commands = commands
end

Instance Attribute Details

#outputObject

Returns the value of attribute output.



3
4
5
# File 'lib/wave_to_json/shell_command.rb', line 3

def output
  @output
end

Instance Method Details

#executeObject



9
10
11
12
13
14
15
16
17
# File 'lib/wave_to_json/shell_command.rb', line 9

def execute
  IO.popen('-') do |p|
    if p.nil?
      $stderr.close
      exec *@commands
    end
    @output = p.read
  end
end

#run_and_return_output_if_successObject



19
20
21
22
# File 'lib/wave_to_json/shell_command.rb', line 19

def run_and_return_output_if_success
  self.execute
  return @output if self.success?
end

#statusObject



29
30
31
# File 'lib/wave_to_json/shell_command.rb', line 29

def status
  $?.exitstatus unless $?.nil?
end

#success?Boolean

Returns:

  • (Boolean)


24
25
26
27
# File 'lib/wave_to_json/shell_command.rb', line 24

def success?
  return false if $?.nil?
  $?.exitstatus == 0 ? true : false
end