从groovy调用ruby脚本 [英] Calling ruby script from groovy

查看:95
本文介绍了从groovy调用ruby脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个groovy脚本,我需要调用一个ruby脚本。



我想将参数传递给Ruby脚本,并希望捕获Ruby的输出脚本在Groovy Script中使用它。有人可以建议我怎么做到这一点?我试过 Process.execute()。它适用于其他dos命令,但不适用于 cmd / c ruby​​ test.rb

解决方案由于ruby文件不是批处理文件,因此不需要使用cmd来执行它。你可以这样做:

$ p $ Process.execute(ruby.exe test.rb)

假设ruby.exe在你的路径上。取决于您的要求的另一种选择可能是使用 JRuby ,这将允许您在JVm上运行Ruby代码并很好地集成与Groovy。


I have a groovy script and I need to call a ruby script.

I would like to pass arguments to Ruby script and would like to capture the output from Ruby script to use it in Groovy Script. Can somebody suggest how I can do this? I tried Process.execute(). It works for other dos commands but not for cmd /c ruby test.rb.

解决方案

Since a ruby file isn't a batch file you don't need to use cmd to execute it. You could do

Process.execute("ruby.exe test.rb")

Assuming ruby.exe is on your path. Another option depending on your requirements may be to use JRuby which will allow you to run ruby code on the JVm and integrate nicely with Groovy.

这篇关于从groovy调用ruby脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆