I'd like to build a promise that spawns a child process using require('child_process').spawn. The process streams its output to stdout and its errors to stderr.
I would like the promise to:
reject(child.stderr stream (or its data))ifchild.stderremits any data.resolve(child.stdout stream)only if no error is emitted.
I'm doing this because I want to chain the promise to:
- a
thenthat processes thechild.stdoutstream (upload the stream to an S3 bucket). - a
catchthat can process the child.stderr stream, allowing me to properly handle errors.
Is it feasible to combine promises and process streams like this ? I was thinking of working around stderr but unsure about whats happening in between to stdout if a lot of data is coming into it and I don't process it fast enough.