process.bend relies on unsafe/foreign
raw source on the hub · import bend-kit-process@0.5.1.0/process.bend as MProcess
Subprocesses and process-level OS access, with byte-exact input and output.
2 imports
import Base import bend-kit-bytes@0.3.3.0/bytes.bend as Bytes
Definitions
def stdin.read source · line 52 · raw
@max:U32 -> IO(Result<&1, &1, Pair(U32, String), String>)
def exit source · line 60 · raw
@code:U32 -> IO(Unit)
def run.result source · line 84 · raw
@r:Result<&1, &1, Pair(U32, String), Pair(U32, Pair(String, String))> -> Result<&1, &1, Pair(U32, String), Pair(U32, Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes))>
def run source · line 92 · raw
@cmd:String -> @args:List<&2, String> -> @env:List<&2, String> -> @cwd:String -> @stdin:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> IO(Result<&1, &1, Pair(U32, String), Pair(U32, Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes))>)
def run.bounded source · line 101 · raw
@cmd:String -> @args:List<&2, String> -> @env:List<&2, String> -> @cwd:String -> @stdin:0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes -> @ms:U32 -> @max_out:U32 -> IO(Result<&1, &1, Pair(U32, String), Pair(U32, Pair(0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes, 0x632652e3c1c0183f12728faf3870bb68/bytes.Bytes))>)
run with run.bounded.raw's deadline, output cap, and group kill.
def timed_out source · line 111 · raw
@timeout:U32 -> @code:U32 -> Bool
A deadline miss: code is the host's ETIMEDOUT, passed as timeout (from etimedout()), since ETIMEDOUT differs between systems.
def too_big source · line 115 · raw
@code:U32 -> Bool
Output past max_out: EFBIG is 27 on Linux and macOS.
Effects (foreign code)
effect run.raw source · line 9 · raw
@cmd:String -> @args:List<&2, String> -> @env:List<&2, String> -> @cwd:String -> @stdin:String -> IO(Result<&1, &1, Pair(U32, String), Pair(U32, Pair(String, String))>)
Environment entries are KEY=VALUE; they override inherited variables. The command is an executable name or path, never a shell expression. Exit status is 0..255, or 128 + the terminating signal number. cwd is the child's directory; relative paths start at the parent's directory.
foreign: effs/process.c, effs/process.js
effect spawn source · line 17 · raw
@cmd:String -> @args:List<&2, String> -> @env:List<&2, String> -> @cwd:String -> IO(Result<&1, &1, Pair(U32, String), Pair(U32, Pair(File, Pair(File, File)))>)
A streaming child: pid, writable stdin, readable stdout and stderr. Close stdin to send EOF; drain both outputs before wait to avoid pipe deadlock.
foreign: effs/process.c, effs/process.js
effect run.bounded.raw source · line 30 · raw
@cmd:String -> @args:List<&2, String> -> @env:List<&2, String> -> @cwd:String -> @stdin:String -> @ms:U32 -> @max_out:U32 -> IO(Result<&1, &1, Pair(U32, String), Pair(U32, Pair(String, String))>)
Like run.raw, bounded. The child leads its own process group. The call ends with SIGKILL to that group while it still holds the unreaped child, then reaps the child. ms is a deadline for the whole call (0: none); a miss is ETIMEDOUT. max_out caps stdout and stderr, each, in bytes (0: none); more is EFBIG. A descendant that keeps an output open holds the call until the deadline. A descendant that leaves the group (setsid, setpgid) escapes the kill. If anything else reaps the child first, nothing is signaled and the call fails with ECHILD; it also refuses (ECHILD) while SIGCHLD is ignored.
foreign: effs/process.c, effs/process.js
effect wait source · line 38 · raw
@pid:U32 -> IO(Result<&1, &1, Pair(U32, String), U32>)
Reaps a spawned child. A signaled child has status 128 + signal number. pid is 1..2147483647; 0 and larger are EINVAL, never group/any-child selectors.
foreign: effs/process.c, effs/process.js
effect etimedout source · line 43 · raw
IO(U32)
The host's ETIMEDOUT error code: 110 on Linux, 60 on macOS.
foreign: effs/process.c, effs/process.js
effect read_stdin source · line 48 · raw
@max:U32 -> IO(Result<&1, &1, Pair(U32, String), String>)
Read up to max bytes from this program's standard input; empty at EOF.
foreign: effs/process.c, effs/process.js
effect exit.raw source · line 56 · raw
@code:U32 -> IO(Unit)
Terminates this program with the supplied status.
foreign: effs/process.c, effs/process.js
effect cwd source · line 63 · raw
IO(Result<&1, &1, Pair(U32, String), String>)
foreign: effs/process.c, effs/process.js
effect chdir source · line 67 · raw
@path:String -> IO(Result<&1, &1, Pair(U32, String), Unit>)
foreign: effs/process.c, effs/process.js
effect hostname source · line 71 · raw
IO(Result<&1, &1, Pair(U32, String), String>)
foreign: effs/process.c, effs/process.js
effect pid source · line 75 · raw
IO(U32)
foreign: effs/process.c, effs/process.js
effect signal.poll source · line 80 · raw
IO(U32)
Install SIGINT/SIGTERM handlers and take one pending event; 0 means none.
foreign: effs/process.c, effs/process.js