I am trying to run a ruby instance as a subprocess of my node program. In fact, everything is in order, but I just can not interact with rubies STDIN and STDOUT. (of course, the ruby program works in my terminal with my keyboard input)
So this is the simplified code that I want to get ...
simpleproc.js
var util = require('util'),
spawn = require('child_process').spawn,
ruby = spawn('ruby', [__dirname + '/process.rb']);
ruby.stdout.on('data', function (data) {
console.log('stdout: ' + data);
});
ruby.stderr.on('data', function (data) {
console.log('stderr: ' + data);
});
ruby.on('exit', function (code) {
console.log('child process exited with code ' + code);
});
ruby.stdin.write("ping\n");
process.rb
f = File.new("process.log", "w")
f.write "=== Hello! ===\n"
STDIN.each_line do |line|
STDOUT.write line
f.write line
end
What about him? I already managed to start another process ... but there is no IO! Nothing happens!
EDIT: I modified the ruby file to show that with a node, the file is only written from === Hello! ===\ninside. Thus, we can say that the ruby file was run correctly, but received nothing from node (I tried to flash after STDOUT.write, but the do statement is never executed.