all your node.js code is fine. Your code only sends data once because your code only receives data once.
puts foo.stdout.on
'$ stdout.flush' , ruby-.
.
.
JS
var spawn = require('child_process').spawn;
var cmd = spawn('ruby', ['testRuby.rb']);
var counter = 0;
cmd.stdout.on('data', function(data) {
counter ++;
console.log('stdout: ' + data);
});
cmd.stderr.on('data', function(data) {
console.log('stderr: ' + data);
});
cmd.on('exit', function(code) {
console.log('exit code: ' + code);
console.log(counter);
});
testRuby.rb
def execute_each_sec(sleep_sec)
yield
sleep sleep_sec
end
5.times do
execute_each_sec(1) do ||
puts "CurrentTime:#{Time.now}"
$stdout.flush
end
end
, $stdout.flush testRuby.rb.
, node.js , testRuby.rb .
. ruby python.
python, sys.stdout.flush(), svkk
Edit:
python -u, .