mirror of
https://github.com/rails/execjs
synced 2023-03-27 23:21:20 -04:00
Merge pull request #38 from wagenet/windows-unicode
CScript Unicode fix
This commit is contained in:
commit
bce2e4f6d1
2 changed files with 24 additions and 3 deletions
|
@ -91,6 +91,7 @@ module ExecJS
|
|||
@runner_path = options[:runner_path]
|
||||
@test_args = options[:test_args]
|
||||
@test_match = options[:test_match]
|
||||
@encoding = options[:encoding]
|
||||
@binary = locate_binary
|
||||
end
|
||||
|
||||
|
@ -120,7 +121,25 @@ module ExecJS
|
|||
|
||||
def exec_runtime(filename)
|
||||
output = nil
|
||||
IO.popen("#{@binary} #{filename} 2>&1") { |f| output = f.read }
|
||||
|
||||
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?
|
||||
output
|
||||
else
|
||||
|
@ -154,5 +173,6 @@ module ExecJS
|
|||
end
|
||||
nil
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -35,8 +35,9 @@ module ExecJS
|
|||
|
||||
JScript = ExternalRuntime.new(
|
||||
:name => "JScript",
|
||||
:command => "cscript //E:jscript //Nologo",
|
||||
:runner_path => ExecJS.root + "/support/jscript_runner.js"
|
||||
:command => "cscript //E:jscript //Nologo //U",
|
||||
:runner_path => ExecJS.root + "/support/jscript_runner.js",
|
||||
:encoding => 'UTF-16LE' # CScript with //U returns UTF-16LE
|
||||
)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue