Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def run_code(code)
- # run something
- stdout_id = $stdout.to_i
- $stdout = StringIO.new
- cmd = <<-EOF
- $stdout = StringIO.new
- begin
- #{code}
- end
- EOF
- begin
- result = Thread.new { Kernel.eval(cmd, @binding) }.value
- rescue SecurityError
- return "illegal"
- rescue Exception => e
- return e
- ensure
- output = get_stdout
- $stdout = IO.open(stdout_id)
- $stdout.close
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement