23 unstable releases

0.13.5 Feb 4, 2021
0.13.4 Apr 13, 2020
0.13.3 Oct 30, 2019
0.12.0 Feb 15, 2019
0.1.0 Feb 20, 2016

#8 in Development tools

Download history 18273/week @ 2021-02-26 22186/week @ 2021-03-05 29011/week @ 2021-03-12 18720/week @ 2021-03-19 21288/week @ 2021-03-26 17586/week @ 2021-04-02 21884/week @ 2021-04-09 19380/week @ 2021-04-16 20143/week @ 2021-04-23 16420/week @ 2021-04-30 23443/week @ 2021-05-07 27216/week @ 2021-05-14 29279/week @ 2021-05-21 28733/week @ 2021-05-28 33039/week @ 2021-06-04 24017/week @ 2021-06-11

87,061 downloads per month
Used in 66 crates (45 directly)

MIT license

105KB
1.5K 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

~135KB