stream.pipe(process.stdout); 问题
exec.start(function(err, stream) { if (err) return; stream.setEncoding(‘utf8’); stream.pipe(process.stdout); // how to get the output result?? // return result; });
如上,如何获取stream流的信息,并返回。thanks.
3 回复
用 Writable Stream
exec.start(function(err, stream) {
if (err) return;
stream.setEncoding(‘utf8’);
var Writable = require('stream').Writable;
var ws = Writable();
ws._write = function (chunk, encoding, next) {
// chunk 就是你要的
next();
}
stream.pipe(ws);
});
@booxood stream是有on回调的
多谢各位