Utility type for any process from () with both stdout and stderr set to "pipe"
Symbol
ReadableSubprocess
Referenced types
interface Subprocess<In extends SpawnOptions.Writable = SpawnOptions.Writable, Out extends SpawnOptions.Readable = SpawnOptions.Readable, Err extends SpawnOptions.Readable = SpawnOptions.Readable>
A process created by Bun.spawn.
This type accepts 3 optional type parameters which correspond to the stdio
array from the options object. Instead of specifying these, you should use one of the following utility types instead:
- ReadableSubprocess (any, pipe, pipe)
- WritableSubprocess (pipe, any, any)
- PipedSubprocess (pipe, pipe, pipe)
- NullSubprocess (ignore, ignore, ignore)
- readonly exitCode: null | number
Synchronously get the exit code of the process
If the process hasn't exited yet, this will return
null
- readonly exited: Promise<number>
The exit code of the process
The promise will resolve when the process exits
- readonly pid: number
The process ID of the child process
const { pid } = Bun.spawn({ cmd: ["echo", "hello"] }); console.log(pid); // 1234
- readonly readable: ReadableToIO<Out>
This returns the same value as Subprocess.stdout
It exists for compatibility with ReadableStream.pipeThrough
- readonly signalCode: null | Signals
Synchronously get the signal code of the process
If the process never sent a signal code, this will return
null
To receive signal code changes, use the
onExit
callback.If the signal code is unknown, it will return the original signal code number, but that case should essentially never happen.
Disconnect the IPC channel to the subprocess. This is only supported if the subprocess was created with the
ipc
option.Kill the process
@param exitCodeThe exitCode to send to the process
This method will tell Bun to wait for this process to exit after you already called
unref()
.Before shutting down, Bun will wait for all subprocesses to exit by default
Get the resource usage information of the process (max RSS, CPU time, etc)
Only available after the process has exited
If the process hasn't exited yet, this will return
undefined
Send a message to the subprocess. This is only supported if the subprocess was created with the
ipc
option, and is another instance ofbun
.Messages are serialized using the JSC serialize API, which allows for the same types that
postMessage
/structuredClone
supports.Before shutting down, Bun will wait for all subprocesses to exit by default
This method will tell Bun to not wait for this process to exit before shutting down.