2017-06-30 3 views
2
const barStream = fs.createWriteStream('bar'); 
const foo = spawn('foo', [], { stdio: ['ignore', barStream, 'inherit'] }); 

wirft einen Fehler:Falscher Wert für stdio stream: Writestream

Incorrect value for stdio stream: WriteStream

Dadurch umgekehrt wie foo.stdout.pipe(barStream) wahrscheinlich den Trick in einigen Fällen der Fall ist.

Aber warum genau WriteStream kann nicht als stdout Stream geliefert werden? Gibt es eine Möglichkeit, barStream für stdout geeignet zu machen?

Antwort

3

Vom documentation for the stdio option, Hervorhebung von mir:

<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'] }); 
    ⋮ 
}); 

Ich werde die Fehlermeldung auf jeden Fall hilfreich sein zugeben kann.

+0

Klar und einfach. Vielen Dank. – estus