aboutsummaryrefslogtreecommitdiff
path: root/docs/guides/process/spawn-stderr.md
diff options
context:
space:
mode:
Diffstat (limited to 'docs/guides/process/spawn-stderr.md')
-rw-r--r--docs/guides/process/spawn-stderr.md31
1 files changed, 31 insertions, 0 deletions
diff --git a/docs/guides/process/spawn-stderr.md b/docs/guides/process/spawn-stderr.md
new file mode 100644
index 000000000..3ea56b24e
--- /dev/null
+++ b/docs/guides/process/spawn-stderr.md
@@ -0,0 +1,31 @@
+---
+name: Read stderr from a child process
+---
+
+When using [`Bun.spawn()`](/docs/api/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"`.
+
+```ts
+const proc = Bun.spawn(["echo", "hello"], {
+ stderr: "pipe",
+});
+proc.stderr; // => ReadableStream
+```
+
+---
+
+To read `stderr` until the child process exits, use the [`Bun.readableStreamToText()`](/docs/api/utils#bun-readablestreamto) convenience function.
+
+```ts
+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](/docs/api/spawn) for complete documentation..