modified to use shellescape instead of gsub

This commit is contained in:
Austin committed 2013-04-15 08:01:24 -07:00
1 parent 6611d818b1
commit e79588fd40
1 file changed
+5 -3
+5 -3
View File
@@ -1,4 +1,5 @@
require "foreman" require "foreman"
require "shellwords"
class Foreman::Process class Foreman::Process
@@ -47,24 +48,25 @@ class Foreman::Process
def run(options={}) def run(options={})
env = @options[:env].merge(options[:env] || {}) env = @options[:env].merge(options[:env] || {})
output = options[:output] || $stdout output = options[:output] || $stdout
runner = "#{Foreman.runner}".shellescape
if Foreman.windows? if Foreman.windows?
Dir.chdir(cwd) do Dir.chdir(cwd) do
Process.spawn env, expanded_command(env), :out => output, :err => output Process.spawn env, expanded_command(env), :out => output, :err => output
end end
elsif Foreman.jruby_18? elsif Foreman.jruby_18?
require "posix/spawn" require "posix/spawn"
wrapped_command = "#{Foreman.runner} -d #{cwd} -p -- #{command}".gsub("'", "\\\\'") wrapped_command = "#{runner} -d #{cwd.shellescape} -p -- #{command}"
POSIX::Spawn.spawn env, wrapped_command, :out => output, :err => output POSIX::Spawn.spawn env, wrapped_command, :out => output, :err => output
elsif Foreman.ruby_18? elsif Foreman.ruby_18?
fork do fork do
$stdout.reopen output $stdout.reopen output
$stderr.reopen output $stderr.reopen output
env.each { |k,v| ENV[k] = v } env.each { |k,v| ENV[k] = v }
wrapped_command = "#{Foreman.runner} -d #{cwd} -p -- #{command}".gsub("'", "\\\\'") wrapped_command = "#{runner} -d #{cwd.shellescape} -p -- #{command}"
Kernel.exec wrapped_command Kernel.exec wrapped_command
end end
else else
wrapped_command = "#{Foreman.runner} -d #{cwd} -p -- #{command}".gsub("'", "\\\\'") wrapped_command = "#{runner} -d #{cwd.shellescape} -p -- #{command}"
Process.spawn env, wrapped_command, :out => output, :err => output Process.spawn env, wrapped_command, :out => output, :err => output
end end
end end