I'm trying to launch a ruby instance as subprocess of my node program. In fact, everything is OK but I just can't interact with the ruby's STDIN and STDOUT. (of course the ruby program works in my terminal with my keyboard input)
So this is a simplified code that I want to get working ...
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's wrong with it ? I've already managed to get an another process working... but here, there is no IO ! Nothing happens !
EDIT: I modified the ruby file to show that, with node, the file is only written with === Hello! ===\n inside. So we can say that, the ruby file is correctly launched but doesn't receive anything from node (I've tried to flush after the STDOUT.write but the do statement is never executed.