A cross-platform library for spawning child processes in Gleam
2

Configure Feed

Select the types of activity you want to include in your feed.

Gleam 47.8%
Shell 33.8%
JavaScript 10.1%
Erlang 8.2%
Makefile 0.2%
23 1 10

Clone this repository

https://tangled.org/becca.monster/child_process https://tangled.org/did:plc:ftst7oajsiso5z2sywxjmfug
git@tangled.org:becca.monster/child_process git@tangled.org:did:plc:ftst7oajsiso5z2sywxjmfug

For self-hosted knots, clone URLs may differ based on your setup.



README.md

child_process#

Package Version Hex Docs

A cross-platform library for spawning child processes in Gleam, inspired by Rust's std::process module.

Run shell commands, execute binaries with full control over stdio, or even launch interactive programs like vim directly from your Gleam code.

gleam add child_process@2

Features#

  • Cross-platform: Works on both Erlang and JavaScript (Node.js) targets
  • Flexible I/O: Capture output, inherit stdio for interactive programs, or stream lines with callbacks
  • Process control: Write to stdin, stop gracefully, or kill processes
  • Builder API: Clean, chainable interface for configuring processes

Usage#

Run a shell command#

import child_process

let assert Ok(output) = child_process.shell("echo Hello, World!")
io.println(output)

Launch interactive programs#

import child_process
import child_process/stdio

// Run vim interactively - stdio is inherited so you can use it normally!
child_process.from_name("vim")
|> child_process.arg("README.md")
|> child_process.stdio(stdio.inherit())
|> child_process.run()

Stream output line-by-line#

import child_process
import child_process/stdio

// Watch mode with live output
child_process.from_name("tailwindcss")
|> child_process.args(["-i", "input.css", "-o", "output.css", "--watch"])
|> child_process.stdio(stdio.lines(fn(line) {
  io.println(line)
}))
|> child_process.spawn()

Further documentation can be found at https://hexdocs.pm/child_process.