gpt4 book ai didi

javascript - stdio 流 : WriteStream 的值不正确

转载 作者:搜寻专家 更新时间:2023-11-01 00:16:46 26 4
gpt4 key购买 nike

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com