简体   繁体   English

如何从Node.js调用Ruby?

[英]How can I invoke Ruby from Node.js?

There are several ways for running JavaScript inside of a Ruby script. 有几种方法可以在Ruby脚本中运行JavaScript。 For example, there is ExecJS which is frequently used for porting NPM modules to Ruby. 例如,ExecJS经常用于将NPM模块移植到Ruby。 So, is there a "ExecRuby" for Node? 那么,Node有“ExecRuby”吗?

You can invoke Ruby like any other shell command using child_process.exec() 您可以使用child_process.exec()调用任何其他shell命令的Ruby

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? 不知道那是不是你要找的东西?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM