lib/cocaine/command_line/runners/process_runner.rb in cocaine-0.5.1 vs lib/cocaine/command_line/runners/process_runner.rb in cocaine-0.5.2

- old
+ new

@@ -1,31 +1,44 @@ # coding: UTF-8 module Cocaine class CommandLine class ProcessRunner - if Process.respond_to?(:spawn) + def self.available? + Process.respond_to?(:spawn) + end - def call(command, env = {}) - input, output = IO.pipe - pid = spawn(env, command, :out => output) - output.close - result = input.read - waitpid(pid) - result - end + def self.supported? + available? && !Cocaine::CommandLine.java? + end - private + def supported? + self.class.supported? + end - def spawn(*args) - Process.spawn(*args) - end + def call(command, env = {}) + input, output = IO.pipe + pid = spawn(env, command, :out => output) + output.close + result = input.read + waitpid(pid) + input.close + result + end - def waitpid(pid) + private + + def spawn(*args) + Process.spawn(*args) + end + + def waitpid(pid) + begin Process.waitpid(pid) + rescue Errno::ECHILD => e + # In JRuby, waiting on a finished pid raises. end - end + end end end -