A cross-platform library for spawning child processes in Gleam
Gleam 48%
Shell 34%
JavaScript 10%
Erlang 8%
Makefile <1%

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.