管道节点中的流(错误:写EPIPE)

时间:2016-05-26 10:36:35

标签: node.js

在Windows10上运行节点v4.4.0。

try {
    var fs = require('fs');
    var path = require('path');
    var spawn = require('child_process').spawn;
    var through = require('through');
} catch (err) {
    throw err;
}

var prettyStream = function () {
    // get the binary directory of bunyan
    var bin = path.resolve(path.dirname(require.resolve('bunyan')), '..', 'bin', 'bunyan');

    var stream = through(function write(data) {
        this.queue(data);
    }, function end() {
        this.queue(null);
    });

    // check if bin var is not empty and that the directory exists
    if (bin && fs.existsSync(bin)) {
        var formatter = spawn(bin, ['-o', 'short'], {
            stdio: [null, process.stdout, process.stderr]
        });
        stream.pipe(formatter.stdin);
    }

    return stream;
}

我收到错误:

Error: write EPIPE
    at exports._errnoException (util.js:870:11)
    at Socket._writeGeneric (net.js:679:26)
    at Socket._write (net.js:698:8)
    at doWrite (_stream_writable.js:301:12)
    at writeOrBuffer (_stream_writable.js:287:5)
    at Socket.Writable.write (_stream_writable.js:215:11)
    at Socket.write (net.js:624:40)
    at Stream.ondata (stream.js:31:26)
    at emitOne (events.js:77:13)
    at Stream.emit (events.js:169:7)

在我的代码中使用它(规范位于:https://github.com/trentm/node-bunyan#constructor-api):

// ..code
stream: prettyStream()
// more code..

无法理解这一点!

0 个答案:

没有答案