mirror of
https://github.com/rails/execjs
synced 2023-03-27 23:21:20 -04:00
Cleanup tmp output
This commit is contained in:
parent
b2afd3155f
commit
87966b6787
1 changed files with 12 additions and 20 deletions
|
@ -143,19 +143,21 @@ module ExecJS
|
||||||
|
|
||||||
if ExecJS.windows?
|
if ExecJS.windows?
|
||||||
def exec_runtime(filename)
|
def exec_runtime(filename)
|
||||||
|
path = Dir::Tmpname.create(['execjs', 'json']) {}
|
||||||
|
begin
|
||||||
command = binary.split(" ") << filename
|
command = binary.split(" ") << filename
|
||||||
|
`#{shell_escape(*command)} 2>&1 > #{path}`
|
||||||
Dir::Tmpname.create(['execjs', 'json']) do |output|
|
output = File.open(path, 'rb', @popen_options) { |f| f.read }
|
||||||
`#{shell_escape(*command)} 2>&1 > #{output}`
|
ensure
|
||||||
output = File.open(output, 'rb', @popen_options) { |f| f.read }
|
File.unlink(path) if path
|
||||||
|
end
|
||||||
|
|
||||||
if $?.success?
|
if $?.success?
|
||||||
return output
|
output
|
||||||
else
|
else
|
||||||
raise RuntimeError, output
|
raise RuntimeError, output
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def shell_escape(*args)
|
def shell_escape(*args)
|
||||||
# see http://technet.microsoft.com/en-us/library/cc723564.aspx#XSLTsection123121120120
|
# see http://technet.microsoft.com/en-us/library/cc723564.aspx#XSLTsection123121120120
|
||||||
|
@ -164,16 +166,6 @@ module ExecJS
|
||||||
arg
|
arg
|
||||||
}.join(" ")
|
}.join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
# See Tempfile.create on Ruby 2.1
|
|
||||||
def create_tempfile(basename)
|
|
||||||
tmpfile = nil
|
|
||||||
Dir::Tmpname.create(basename) do |tmpname|
|
|
||||||
mode = File::WRONLY | File::CREAT | File::EXCL
|
|
||||||
tmpfile = File.open(tmpname, mode, 0600)
|
|
||||||
end
|
|
||||||
tmpfile
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
def exec_runtime(filename)
|
def exec_runtime(filename)
|
||||||
io = IO.popen(binary.split(' ') << filename, @popen_options.merge({err: [:child, :out]}))
|
io = IO.popen(binary.split(' ') << filename, @popen_options.merge({err: [:child, :out]}))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue