呼吁在C#中的Ruby脚本 [英] calling a ruby script in c#

查看:216
本文介绍了呼吁在C#中的Ruby脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何做出一个Ruby脚本调用,并传递一些参数,一旦脚本执行完毕,结果返回的控制权交还给C#代码?


解决方案

 无效的runScript()
{
使用(进程p =新工艺())
{
的ProcessStartInfo信息=新的ProcessStartInfo(红宝石C:\rubyscript.rb);
info.Arguments =ARGS //设置ARGS
info.RedirectStandardInput = TRUE;
info.RedirectStandardOutput = TRUE;
info.UseShellExecute = FALSE;
p.StartInfo =信息;
p.Start();
字符串输出= p.StandardOutput.ReadToEnd();
//输出过程
}
}


How do make a call to a ruby script and pass some parameters and once the script is finished return the control back to the c# code with the result?

解决方案

    void runScript()
    {
        using (Process p = new Process())
        {
            ProcessStartInfo info = new ProcessStartInfo("ruby C:\rubyscript.rb");
            info.Arguments = "args"; // set args
            info.RedirectStandardInput = true;
            info.RedirectStandardOutput = true;
            info.UseShellExecute = false;
            p.StartInfo = info;
            p.Start();
            string output = p.StandardOutput.ReadToEnd();
            // process output
        }
    }

这篇关于呼吁在C#中的Ruby脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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