Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从Node.js派生Ruby-如何在Ruby文件中要求?_Ruby_Node.js_Spawn - Fatal编程技术网

从Node.js派生Ruby-如何在Ruby文件中要求?

从Node.js派生Ruby-如何在Ruby文件中要求?,ruby,node.js,spawn,Ruby,Node.js,Spawn,我已经成功地从我的节点应用程序中生成了一个ruby脚本。然而,在我的Ruby脚本中,我需要一些gem和文件,而且在执行require时,node.js似乎没有得到任何响应 下面是它的外观: var cp = require('child_process') var ruby_child = cp.spawn('ruby',['libs/scorer/test.rb']); var result = ''; ruby_child.stdout.on('data', function(data

我已经成功地从我的节点应用程序中生成了一个ruby脚本。然而,在我的Ruby脚本中,我需要一些gem和文件,而且在执行require时,node.js似乎没有得到任何响应

下面是它的外观:

var cp = require('child_process')
var ruby_child = cp.spawn('ruby',['libs/scorer/test.rb']);  

var result = '';
ruby_child.stdout.on('data', function(data) {
        result += data.toString();
});

ruby_child.on('close', function() {
        console.log(result);
});
我的Ruby脚本如下所示:

require 'utils' # if I remove this line, I can get the response.

# Does it have an argument?
if ARGV.nil? || ARGV.empty?
  p 'test'
  exit
end
这可能是require行失败的原因。Ruby程序向STDERR发送了一些错误状态,然后退出,您的js程序没有捕获STDERR输出

在js程序中添加一些STDERR捕获代码,以获取问题的诊断信息。您可能会发现Ruby在$LOAD\u PATH中找不到所需的库

ruby_child.stderr.on('data', function(data) {
    console.log("ERROR --- " + data);
});