Class: Cindy::Executor::Local

Inherits:
Base
  • Object
show all
Defined in:
lib/cindy/executor/local.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#close, #exec, #exec!, from_uri

Constructor Details

#initialize(uri, logger) ⇒ Local

Returns a new instance of Local.



11
12
13
# File 'lib/cindy/executor/local.rb', line 11

def initialize(uri, logger)
    super logger
end

Class Method Details

.handle?(uri) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/cindy/executor/local.rb', line 7

def self.handle?(uri)
    [ nil, 'file' ].include? uri.scheme
end

Instance Method Details

#exec_imp(command, stdin_str) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/cindy/executor/local.rb', line 15

def exec_imp(command, stdin_str)
    exit_status = 1
    stdout_str = stderr_str = ''
    begin
        Open3.popen3({ 'PATH' => "#{ENV['PATH']}:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin" }, command) do |stdin, stdout, stderr, wait_thr|
            if stdin_str
                stdin.write stdin_str
                stdin.close
            end
            stdout_str = stdout.read
            stderr_str = stderr.read
            exit_status = wait_thr.value.exitstatus
        end
    rescue Errno::ENOENT => e
        stderr_str = e.message
    end
    [ stdout_str, stderr_str, exit_status ]
end