method

bun.Spawn.BaseOptions.onExit

subprocess: Subprocess<In, Out, Err>,
exitCode: null | number,
signalCode: null | number | Signals,
error?: ErrorLike
): void | Promise<void>;

Callback that runs when the Subprocess exits

This is called even if the process exits with a non-zero exit code.

Warning: this may run before the Bun.spawn function returns.

An alternative is await subprocess.exited.

@param error

If an error occurred in the call to waitpid2, this is the error.

const subprocess = spawn({
 cmd: ["echo", "hello"],
 onExit: (subprocess, code) => {
   console.log(`Process exited with code ${code}`);
  },
});