Runtime
Bundler
Package Manager
Test Runner
Guides
Reference
Blog
Install Bun
Guides Process & System

Read stderr from a child process

When you spawn a child process with Bun.spawn(), it inherits the stderr of the spawning process. To read and handle stderr instead, 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 .text().

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

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

See Child processes.

On this page

No Headings