Files
bun.sh/docs/guides/process/spawn-stderr.md
Colin McDonnell 112030481f More guides and fixing links (#3960)
* More guides

* WIP

* Updates

* Fix
2023-08-03 16:31:05 -07:00

779 B

name
name
Read stderr from a child process

When using Bun.spawn(), the child process inherits the stderr of the spawning process. If instead you'd prefer to read and handle stderr, set the stderr option to "pipe".

const proc = Bun.spawn(["echo", "hello"], {
  stderr: "pipe",
});
proc.stderr; // => ReadableStream

To read stderr until the child process exits, use the Bun.readableStreamToText() convenience function.

const proc = Bun.spawn(["echo", "hello"], {
  stderr: "pipe",
});

const errors: string = await Bun.readableStreamToText(proc.stderr);
if (errors) {
  // handle errors
}

See Docs > API > Child processes for complete documentation.