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/