From 0c27f78d46b6948e44adcd3b5d240cbcdbf0aeaa Mon Sep 17 00:00:00 2001 From: David Dollar Date: Thu, 22 Dec 2011 16:33:49 -0500 Subject: [PATCH] compatibility with ruby 1.8 --- lib/foreman/engine.rb | 2 +- lib/foreman/process.rb | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/foreman/engine.rb b/lib/foreman/engine.rb index 1e622dc..6047028 100644 --- a/lib/foreman/engine.rb +++ b/lib/foreman/engine.rb @@ -115,7 +115,7 @@ private ###################################################################### print "#{Time.now.strftime("%H:%M:%S")} #{pad_process_name(name)} | " print Term::ANSIColor.reset print message.chomp - puts + puts "" end def print(message=nil) diff --git a/lib/foreman/process.rb b/lib/foreman/process.rb index 3d0e74d..4f00de7 100644 --- a/lib/foreman/process.rb +++ b/lib/foreman/process.rb @@ -27,9 +27,21 @@ class Foreman::Process private + def fork_with_io(command) + io = case RUBY_VERSION + when /^1\.9\./ + IO.popen([Foreman.runner, replace_command_env(command)], "w+") + when /^1\.8\./ + full_command = replace_command_env(command).gsub("'", "\\'") + IO.popen("#{Foreman.runner} '#{full_command}'", "w+") + else + raise "Unknown Ruby version: #{RUBY_VERSION}" + end + [ io, io.pid ] + end + def run_process(command, pipe) - io = IO.popen([Foreman.runner, replace_command_env(command)], "w+") - @pid = io.pid + io, @pid = fork_with_io(command) trap("SIGTERM") { "got sigterm for %d" % @pid } output pipe, "started with pid %d" % @pid Thread.new do