Skip to content

Instantly share code, notes, and snippets.

@agrare
Created August 5, 2021 19:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agrare/81ac24931b2ba46751cc61957df29747 to your computer and use it in GitHub Desktop.
Save agrare/81ac24931b2ba46751cc61957df29747 to your computer and use it in GitHub Desktop.
require "execjs"
class ExecJS::ExternalRuntime
def exec_runtime(filename)
r, w = IO.pipe
pid = Kernel.spawn("#{binary} #{filename}", :out => w, :err=>[:child, :out])
puts "#{binary} PID: #{pid}"
w.close
Process.wait(pid)
output = r.read
r.close
puts "output: #{output.inspect}"
puts "last command: #{$?.inspect}"
if $?.success?
output
else
raise exec_runtime_error(output)
end
end
end
ExecJS.compile(File.read('/tmp/uglify.js'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment