javascript - stdio 流 : WriteStream 的值不正确

标签 javascript node.js

const barStream = fs.createWriteStream('bar');
const foo = spawn('foo', [], { stdio: ['ignore', barStream, 'inherit'] });

抛出一个错误:

Incorrect value for stdio stream: WriteStream

foo.stdout.pipe(barStream) 这样反向执行此操作在某些情况下可能会成功。

但是为什么 WriteStream 不能作为标准输出流提供呢?有没有办法让 barStream 适合 stdout?

最佳答案

来自documentation for the stdio option ,强调我的:

<Stream> object - Share a readable or writable stream that refers to a tty, file, socket, or a pipe with the child process. The stream's underlying file descriptor is duplicated in the child process to the fd that corresponds to the index in the stdio array. Note that the stream must have an underlying descriptor (file streams do not until the 'open' event has occurred).

所以:

const barStream = fs.createWriteStream('bar');

barStream.on('open', () => {
    const foo = spawn('foo', [], { stdio: ['ignore', barStream, 'inherit'] });
    ⋮
});

我承认错误消息肯定会更有帮助。

关于javascript - stdio 流 : WriteStream 的值不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44846696/

相关文章:

javascript - 如何获取点击查询的值?

javascript - 如何将多个中间件功能封装成一个?

node.js - 我们如何在 node.js 中使用 Firebase Auth 创建用户?

javascript - 如何在鼠标移出时结束 .switchClass 事件?

javascript - JSP:如何将下拉列表的所有(选中和未选中)选项传递给 servlet?

javascript - JavaScript 中的虚函数是什么?

node.js - Windows 中 Electron 的 SQLITE3 安装错误

javascript - Firebug:console.trace 没有输出

mysql - 多个控制字段在 Node.js 应用程序中不起作用

node.js - 使用 mongoose 时在 mongodb 中找不到 Db