Program runner for Bend 2. Pass argv as a
list of strings — no shell — and get back exit status, stdout, and stderr.
start returns a pid without waiting; par runs several jobs together.
Helpers join argv and read answers.
Every argument reaches the program whole, newlines and all. An argv that
could not arrive whole, one with no program name or with NUL inside an
argument, is refused: run answers status 127 and start answers 0, and
nothing is run. In par, a refused job answers 127 in its own place.
What snap guarantees is listed in SPEC.md: each requirement is
either proved by a quantified law in LAWS.bend (proofs in
PROOF.bend, shared lemmas in check/) or named as a trusted
assumption about the C and JS effects that start programs. The reasoning is
in docs/rfc/snap-spec.md.
With Bend alone there is nothing to
install: import snap by its hub name and bend fetches it from
the hub into ~/.bend/lib on the first run.
0xabe575924687afad4cee1a2c1194d639 is snap v1.1.0.
import 0xabe575924687afad4cee1a2c1194d639/main.bend as Snap
Or with ez, which records the
package in ez.toml (ez init makes one):
ez add Emerging-Patterns/snap
run answers with the exit status on its own first line, then stdout and
stderr together. Snap.code reads the status; Snap.text reads the body.
import 0xabe575924687afad4cee1a2c1194d639/main.bend as Snap
def main() -> IO(Unit):
do IO<Unit>:
+out : String <- Snap.run(["echo", "hello"])
IO.print(Snap.code(out))
IO.print(Snap.text(out))
git clone https://github.com/Emerging-Patterns/snap
cd snap
mkdir -p bin
bend examples/demo/main.bend -o bin/demo.bin
bin/demo.bin