最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Incorrect value for stdio stream: WriteStream - Stack Overflow

programmeradmin2浏览0评论
const barStream = fs.createWriteStream('bar');
const foo = spawn('foo', [], { stdio: ['ignore', barStream, 'inherit'] });

throws an error:

Incorrect value for stdio stream: WriteStream

Doing this in reverse like foo.stdout.pipe(barStream) likely does the trick in some cases.

But why exactly WriteStream cannot be supplied as stdout stream? Is there a way to make barStream suitable for stdout?

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

throws an error:

Incorrect value for stdio stream: WriteStream

Doing this in reverse like foo.stdout.pipe(barStream) likely does the trick in some cases.

But why exactly WriteStream cannot be supplied as stdout stream? Is there a way to make barStream suitable for stdout?

Share Improve this question asked Jun 30, 2017 at 12:38 Estus FlaskEstus Flask 224k79 gold badges472 silver badges611 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 10

From the documentation for the stdio option, emphasis mine:

<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).

So:

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

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

I’ll admit that error message could definitely be more helpful.

发布评论

评论列表(0)

  1. 暂无评论