28 releases (3 stable)

1.1.1 Nov 9, 2025
1.0.0 May 7, 2025
0.13.7 Dec 22, 2023
0.13.6 Nov 29, 2022
0.1.0 Feb 20, 2016

#2 in Command line utilities

Download history 263405/week @ 2026-01-19 301330/week @ 2026-01-26 320100/week @ 2026-02-02 324578/week @ 2026-02-09 295591/week @ 2026-02-16 340249/week @ 2026-02-23 385714/week @ 2026-03-02 387560/week @ 2026-03-09 402639/week @ 2026-03-16 332692/week @ 2026-03-23 346366/week @ 2026-03-30 305872/week @ 2026-04-06 342121/week @ 2026-04-13 379480/week @ 2026-04-20 362463/week @ 2026-04-27 394310/week @ 2026-05-04

1,502,262 downloads per month
Used in 484 crates (233 directly)

MIT license

135KB
2K SLoC

duct.rs Actions Status crates.io docs.rs

Duct is a library for running child processes. Duct makes it easy to build pipelines and redirect IO like a shell. At the same time, Duct helps you write correct, portable code: whitespace is never significant, errors from child processes get reported by default, and a variety of gotchas, bugs, and platform inconsistencies are handled for you the Right Way™.

Examples

Run a command without capturing any output. Here "hi" is printed directly to the terminal:

use duct::cmd;
cmd!("echo", "hi").run()?;

Capture the standard output of a command. Here "hi" is returned as a String:

let stdout = cmd!("echo", "hi").read()?;
assert_eq!(stdout, "hi");

Capture the standard output of a pipeline:

let stdout = cmd!("echo", "hi").pipe(cmd!("sed", "s/i/o/")).read()?;
assert_eq!(stdout, "ho");

Merge standard error into standard output and read both incrementally:

use duct::cmd;
use std::io::prelude::*;
use std::io::BufReader;

let big_cmd = cmd!("bash", "-c", "echo out && echo err 1>&2");
let reader = big_cmd.stderr_to_stdout().reader()?;
let mut lines = BufReader::new(reader).lines();
assert_eq!(lines.next().unwrap()?, "out");
assert_eq!(lines.next().unwrap()?, "err");

Children that exit with a non-zero status return an error by default:

let result = cmd!("false").run();
assert!(result.is_err());
let result = cmd!("false").unchecked().run();
assert!(result.is_ok());

Dependencies

~0.1–10MB
~33K SLoC