我现在有一个使用 CoffeeScript 的工作示例:
childproc = require "child_process"
couchdb = childproc.spawn "couchdb"
couchdb.stdout.setEncoding "utf8"
buffer = ""
couchdb.stdout.on "data", (data) ->
lines = (buffer + data).split(/\r?\n/)
buffer = lines.pop()
lines.forEach (line, index) ->
console.log line
couchdb.stdout.on "end", ->
if buffer.length > 0
console.log buffer
buffer = ""
console.log 'process ended'
有关 CS、Iced CS 和 JS 中更完整的示例,请参阅我的要点
编辑
这是 Javascript 中的输出:
var buffer, childproc, couchdb;
childproc = require("child_process");
couchdb = childproc.spawn("couchdb");
couchdb.stdout.setEncoding("utf8");
buffer = "";
couchdb.stdout.on("data", function(data) {
var lines;
lines = (buffer + data).split(/\r?\n/);
buffer = lines.pop();
return lines.forEach(function(line, index) {
return console.log(line);
});
});
couchdb.stdout.on("end", function() {
if (buffer.length > 0) {
console.log(buffer);
buffer = "";
}
return console.log('process ended');
});