1
0
Fork 0
mirror of https://github.com/rails/execjs synced 2023-03-27 23:21:20 -04:00

Define sh helper specific to ruby env

This commit is contained in:
Joshua Peek 2011-09-07 15:35:45 -05:00
parent bce2e4f6d1
commit c9278dbe8a

View file

@ -120,26 +120,7 @@ module ExecJS
end end
def exec_runtime(filename) def exec_runtime(filename)
output = nil output = sh("#{@binary} #{filename} 2>&1")
cmd = "#{@binary} #{filename} 2>&1"
if @encoding
if "".respond_to?(:encode)
IO.popen(cmd, :internal_encoding => 'UTF-8', :external_encoding => @encoding) do |f|
output = f.read
end
else
require 'iconv'
IO.popen(cmd) do |f|
ic = Iconv.new('UTF-8', @encoding)
output = ic.iconv(f.read)
end
end
else
IO.popen(cmd){|f| output = f.read }
end
if $?.success? if $?.success?
output output
else else
@ -174,5 +155,26 @@ module ExecJS
nil nil
end end
if "".respond_to?(:force_encoding)
def sh(command)
output, options = nil, {}
options[:external_encoding] = @encoding if @encoding
IO.popen(command, options) { |f| output = f.read }
output
end
else
require "iconv"
def sh(command)
output = nil
IO.popen(command) { |f| output = f.read }
if @encoding
Iconv.new('UTF-8', @encoding).iconv(output)
else
output
end
end
end
end end
end end