Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/oconnor663/duct.rs
a Rust library for running child processes
https://github.com/oconnor663/duct.rs
Last synced: 5 days ago
JSON representation
a Rust library for running child processes
- Host: GitHub
- URL: https://github.com/oconnor663/duct.rs
- Owner: oconnor663
- License: mit
- Created: 2016-02-20T18:54:26.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-08-01T22:03:09.000Z (3 months ago)
- Last Synced: 2024-10-14T20:58:29.540Z (21 days ago)
- Language: Rust
- Homepage:
- Size: 351 KB
- Stars: 821
- Watchers: 5
- Forks: 34
- Open Issues: 33
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-rust-cn - oconnor663/duct.rs - ci.org/oconnor663/duct.rs.svg?branch=master">](https://travis-ci.org/oconnor663/duct.rs) (Libraries / Command-line)
- awesome-rust - oconnor663/duct.rs - ci.org/oconnor663/duct.rs.svg?branch=master">](https://travis-ci.org/oconnor663/duct.rs) (Libraries / Command-line)
- awesome-rust - oconnor663/duct.rs
- awesome-rust-cn - oconnor663/duct.rs
- awesome-rust-zh - oconnor663/duct.rs - 子进程管道化和 IO 重定向的构建器[<img src="https://api.travis-ci.org/oconnor663/duct.rs.svg?branch=master">](https://travis-ci.org/oconnor663/duct.rs) (库 / 命令行)
- awesome-rust - oconnor663/duct.rs - A builder for subprocess pipelines and IO redirection (Libraries / Command-line)
- awesome-rust - oconnor663/duct.rs - ci.org/oconnor663/duct.rs.svg?branch=master">](https://travis-ci.org/oconnor663/duct.rs) (库 Libraries / 命令行 Command-line)
- fucking-awesome-rust - oconnor663/duct.rs - A builder for subprocess pipelines and IO redirection (Libraries / Command-line)
- fucking-awesome-rust - oconnor663/duct.rs - A builder for subprocess pipelines and IO redirection (Libraries / Command-line)
README
# duct.rs [![Actions Status](https://github.com/oconnor663/duct.rs/workflows/tests/badge.svg)](https://github.com/oconnor663/duct.rs/actions) [![crates.io](https://img.shields.io/crates/v/duct.svg)](https://crates.io/crates/duct) [![docs.rs](https://docs.rs/duct/badge.svg)](https://docs.rs/duct)
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](https://github.com/oconnor663/duct.py/blob/master/gotchas.md)
are handled for you the Right Way™.- [Documentation](https://docs.rs/duct)
- [Crate](https://crates.io/crates/duct)
- [GitHub repo](https://github.com/oconnor663/duct.rs)
- [the same library, in Python](https://github.com/oconnor663/duct.py)Examples
--------Run a command without capturing any output. Here "hi" is printed directly
to the terminal:```rust
use duct::cmd;
cmd!("echo", "hi").run()?;
```Capture the standard output of a command. Here "hi" is returned as a
`String`:```rust
let stdout = cmd!("echo", "hi").read()?;
assert_eq!(stdout, "hi");
```Capture the standard output of a pipeline:
```rust
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:
```rust
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:
```rust
let result = cmd!("false").run();
assert!(result.is_err());
let result = cmd!("false").unchecked().run();
assert!(result.is_ok());
```