Node.js错误:写EPIPE

时间:2018-06-14 06:25:51

标签: javascript node.js child-process node8.2

我有像

这样的代码
const child = async (command, options, logger) =>
  new Promise((resolve, reject) => {
    const start = Date.now();

    const child = child_process
      .spawn(command, options)
      .on('error', (err) => reject(err))
      .on('exit', (code, signal) => {
       const duration = Date.now() - start;
       resolve({ code, signal, duration });
      });

    child.stdout.write('[worker]'); //New addition
    child.stdout.pipe(logger.stream());
    child.stderr.write('[worker]'); //New addition
    child.stderr.pipe(logger.stream());
  });

我想在[worker]child.stdout.pipe child.stdout.write之前的日志中记录logger.stream

我收到类似

的错误
[worker] waitFor, exit 0
does this even print?
events.js:183
     throw er; // Unhandled 'error' event
     ^
Error: write EPIPE
at _errnoException (util.js:992:11)
at WriteWrap.afterWrite [as oncomplete] (net.js:864:14)

我使用calledCount,closedpipe进行了调试。与此相关的测试位于lib/worker.test.js here

我可以在导致此错误的原因上获得一些帮助吗?

0 个答案:

没有答案