Created
May 5, 2015 13:57
-
-
Save threez/2fc92a0aac1f767852ca to your computer and use it in GitHub Desktop.
Simply execute perl code from ruby
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 'open3' | |
module Perl | |
def self.exec(code) | |
pstdin, pstdout, pstderr = Open3.popen3('perl') | |
pstdin.write code | |
pstdin.close | |
data = pstdout.read | |
err = pstderr.read | |
if err.size > 0 | |
raise err | |
end | |
data | |
ensure | |
pstdout.close | |
pstderr.close | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment