AgentSkillsCN

Bun Read stderr from a child process

从子进程中读取 stderr

SKILL.md
--- frontmatter
name: Bun Read stderr from a child process
description: Read stderr from a child process

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".

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

proc.stderr; // => ReadableStream

To read stderr until the child process exits, use .text()

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

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

See Docs > API > Child processes for complete documentation.