Class: Cliver::ShellCapture
- Inherits:
-
Object
- Object
- Cliver::ShellCapture
- Defined in:
- lib/cliver/shell_capture.rb
Instance Attribute Summary collapse
-
#command_found ⇒ Object
readonly
Returns the value of attribute command_found.
-
#stderr ⇒ Object
readonly
Returns the value of attribute stderr.
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
Instance Method Summary collapse
- #initialize(command) ⇒ void constructor
Constructor Details
#initialize(command) ⇒ void
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/cliver/shell_capture.rb', line 13 def initialize(command) command = command.shelljoin if command.kind_of?(Array) @stdout = @stderr = '' begin Open3.popen3(command) do |i, o, e| @stdout = o.read.chomp @stderr = e.read.chomp end # Fix for ruby 1.8.7 (and probably earlier): # Open3.popen3 does not raise anything there, but the error goes to STDERR. if @stderr =~ /open3.rb:\d+:in `exec': No such file or directory -.*\(Errno::ENOENT\)/ or @stderr =~ /An exception occurred in a forked block\W+No such file or directory.*\(Errno::ENOENT\)/ @stderr = '' @command_found = false else @command_found = true end rescue Errno::ENOENT, IOError @command_found = false end end |
Instance Attribute Details
#command_found ⇒ Object (readonly)
Returns the value of attribute command_found.
5 6 7 |
# File 'lib/cliver/shell_capture.rb', line 5 def command_found @command_found end |
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
5 6 7 |
# File 'lib/cliver/shell_capture.rb', line 5 def stderr @stderr end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
5 6 7 |
# File 'lib/cliver/shell_capture.rb', line 5 def stdout @stdout end |