Spawn a new process
Symbol
spawnSync
function spawnSync<Opts extends OptionsObject<Writable, Readable, Readable>>(options: Opts & { cmd: string[]; onExit: undefined }): OptionsToSyncSubprocess<Opts>
function spawnSync<Opts extends OptionsObject<Writable, Readable, Readable>>(cmds: string[], options?: Opts): OptionsToSyncSubprocess<Opts>
Synchronously spawn a new process
const {stdout} = Bun.spawnSync(["echo", "hello"]);
console.log(stdout.toString()); // "hello\n"
Internally, this uses posix_spawn(2)
@param cmds
The command to run
The first argument will be resolved to an absolute executable path. It must be a file, not a directory.
If you explicitly set PATH
in env
, that PATH
will be used to resolve the executable instead of the default PATH
.
To check if the command exists before running it, use Bun.which(bin)
.
Referenced types
type OptionsToSyncSubprocess<Opts extends OptionsObject> = Opts extends OptionsObject<any, infer Out, infer Err> ? SyncSubprocess<Readable extends Out ? 'pipe' : Out, Readable extends Err ? 'pipe' : Err> : SyncSubprocess<Readable, Readable>