如何从Node.js调用Ruby? [英] How can I invoke Ruby from Node.js?

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

问题描述

在Ruby脚本中运行JavaScript有几种方法。例如,ExecJS经常用于将NPM模块移植到Ruby。那么,节点是否有ExecRuby?

There are several ways for running JavaScript inside of a Ruby script. For example, there is ExecJS which is frequently used for porting NPM modules to Ruby. So, is there a "ExecRuby" for Node?

推荐答案

您可以使用 child_process.exec()

You can invoke Ruby like any other shell command using child_process.exec()

var exec = require("child_process").exec;

exec('ruby -e "puts \'Hello from Ruby!\'"', function (err, stdout, stderr) {
    console.log(stdout);
});

不知道这是不是你想要的?

Don't know if that's what you're looking for?

这篇关于如何从Node.js调用Ruby?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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