0
class CommandError < RuntimeError; end
0
class Failed < CommandError; end
0
class BadCommand < CommandError; end
0
+ @logger ||= Log4r::Logger["handler::client"]
0
- logger.debug(&block) if logger
0
def run_cmd(executable, *args)
0
args.collect! {|arg| arg =~ /\s|\*|\?|"|\n|\r/ ? %Q('#{arg}') : arg}
0
args.collect! {|arg| arg ? arg : '""'}
0
cmd = %Q|#{executable} #{args.join(' ')}|
0
+
logger.debug {"> " + cmd}
0
original_language = ENV["LANGUAGE"]
0
-
debug {value} unless (value || "").strip.empty?
0
+
logger.debug {"< " + value} unless (value || "").strip.empty?
0
ENV["LANGUAGE"] = original_language
0
- debug {"> #{cmd.inspect}"}
0
pid, stdin, stdout, stderr = Open4::popen4(cmd)
0
_, cmdstatus = Process.waitpid2(pid)
0
- debug {"> #{cmdstatus.inspect}, success? #{cmdstatus.success?}, status: #{cmdstatus.exitstatus}"}
0
return stdout.read if cmd =~ /status/ && cmdstatus.exitstatus == 1
0
raise CommandError, "#{cmd.inspect} exited with status: #{cmdstatus.exitstatus}\n#{stderr.read}" unless cmdstatus.success?
Comments
No one has commented yet.