Class: WaveToJson::ShellCommand
- Inherits:
-
Object
- Object
- WaveToJson::ShellCommand
- Defined in:
- lib/wave_to_json/shell_command.rb
Instance Attribute Summary collapse
-
#output ⇒ Object
Returns the value of attribute output.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(commands) ⇒ ShellCommand
constructor
A new instance of ShellCommand.
- #run_and_return_output_if_success ⇒ Object
- #status ⇒ Object
- #success? ⇒ Boolean
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
#output ⇒ Object
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
#execute ⇒ Object
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_success ⇒ Object
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 |
#status ⇒ Object
29 30 31 |
# File 'lib/wave_to_json/shell_command.rb', line 29 def status $?.exitstatus unless $?.nil? end |
#success? ⇒ 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 |