bungibindies/bun/spawn
PARTIAL IMPLEMENTATION OF Bun.spawn()
AND Bun.spawnSync()
Types
pub type AsyncSubprocessObject
pub type OptionsToSubprocess {
OptionsToSubprocess(
cmd: List(String),
cwd: Option(String),
env: Option(Dict(String, String)),
stderr: Option(Out),
stdout: Option(Out),
)
}
Constructors
-
OptionsToSubprocess( cmd: List(String), cwd: Option(String), env: Option(Dict(String, String)), stderr: Option(Out), stdout: Option(Out), )
Arguments
- cmd
-
The command and arguments to run.
- cwd
-
The working directory to run the command in. Defaults to the current working directory.
- env
-
Environment variables to set for the command.
- stderr
-
Where to send the error output of the command. If not specified, defaults to
Pipe
for async andInherit
for sync.If
Pipe
, the output will be available in thestderr
property of the result. IfInherit
, the output will be sent to the same place as the parent process. IfIgnore
, the output will be send nowhere and will instead be ignored. - stdout
-
Where to send the output of the command. If not specified, defaults to
Pipe
for async andInherit
for sync.If
Pipe
, the output will be available in thestdout
property of the result. IfInherit
, the output will be sent to the same place as the parent process. IfIgnore
, the output will be send nowhere and will instead be ignored.
pub type SubProcess {
AsyncSubprocess(AsyncSubprocessObject)
SyncSubprocess(SyncSubprocessObject)
}
Constructors
-
AsyncSubprocess(AsyncSubprocessObject)
-
SyncSubprocess(SyncSubprocessObject)
pub type SyncSubprocessObject
Values
pub fn async(with options: OptionsToSubprocess) -> SubProcess
This function is used to spawn a new process asynchronously.
It returns an AsyncSubprocess
object that can be used AsyncSubprocessDatah the spawned process.
pub fn exit_code(
from subprocess: AsyncSubprocessObject,
) -> Result(Int, Nil)
Synchronously get the exit code of the subprocess
If the process hasn’t exited yet, this will return Error(Nil)
pub fn exited(
from subprocess: AsyncSubprocessObject,
) -> Promise(Int)
Asynchronously get the exit code of the subprocess The promise will resolve when the process exits.
pub fn kill(
from subprocess: AsyncSubprocessObject,
code killcode: Option(Int),
) -> Nil
Kills a subprocess
pub fn reref(from subprocess: AsyncSubprocessObject) -> Nil
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
pub fn stderr(from subprocess: SubProcess) -> Result(String, Nil)
Attempts to fetch stderr from the subprocess.
pub fn stdout(from subprocess: SubProcess) -> Result(String, Nil)
Attempts to fetch stdout from the subprocess.
pub fn success(from subprocess: SyncSubprocessObject) -> Bool
Get the success status from the subprocess.
pub fn sync(with options: OptionsToSubprocess) -> SubProcess
This function is used to spawn a new process synchronously.
It returns a SyncSubprocess
object that can be used to interact with the spawned process.