Promise resolving to child stream stdout and rejecting child stream stderr

Viewed 1271

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)) if child.stderr emits 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 then that processes the child.stdout stream (upload the stream to an S3 bucket).
  • a catch that 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.

1 Answers
Related