我已經工作的例子,現在使用的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'
See my gist for a fuller example in 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');
});
共享資格對任何人都沒有價值 - 我不知道笑臉是什麼。 – 2012-07-08 22:36:53
+1 @Cirrostratus,-1 dscape。 – 2012-07-09 01:10:41