property
Spawn.SpawnOptions.terminal
terminal?: TerminalOptions | Terminal
Spawn the subprocess with a pseudo-terminal (PTY) attached.
When this option is provided:
stdin,stdout, andstderrare all connected to the terminal- The subprocess sees itself running in a real terminal (
isTTY = true) - Access the terminal via
subprocess.terminal subprocess.stdin,subprocess.stdout,subprocess.stderrreturnnull
Only available on POSIX systems (Linux, macOS).
const proc = Bun.spawn(["bash"], {
terminal: {
cols: 80,
rows: 24,
data: (term, data) => console.log(data.toString()),
},
});
proc.terminal.write("echo hello\n");
await proc.exited;
proc.terminal.close();You can also pass an existing Terminal object for reuse across multiple spawns:
const terminal = new Bun.Terminal({ ... });
const proc1 = Bun.spawn(["echo", "first"], { terminal });
await proc1.exited;
const proc2 = Bun.spawn(["echo", "second"], { terminal });
await proc2.exited;
terminal.close();