Created
August 5, 2021 19:26
-
-
Save agrare/81ac24931b2ba46751cc61957df29747 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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