15 releases (7 stable)

1.1.2 Mar 16, 2024
1.1.1 Nov 9, 2021
1.0.2 Aug 29, 2021
0.13.0 Sep 8, 2020
0.9.0 Sep 5, 2020

#309 in Development tools

Download history 43/week @ 2024-01-21 48/week @ 2024-01-28 27/week @ 2024-02-04 61/week @ 2024-02-11 73/week @ 2024-02-18 130/week @ 2024-02-25 71/week @ 2024-03-03 140/week @ 2024-03-10 669/week @ 2024-03-17 50/week @ 2024-03-24 233/week @ 2024-03-31 78/week @ 2024-04-07 189/week @ 2024-04-14 90/week @ 2024-04-21 56/week @ 2024-04-28 91/week @ 2024-05-05

434 downloads per month
Used in 4 crates (2 directly)

Apache-2.0

17KB
291 lines

command-run

crates.io Documentation

Rust library for running a command in a subprocess.

This library is a thin wrapper around the std::process::Command type with a few additional convenient features:

  • Print or log the command before running it
  • Optionally return an error if the command is not successful
  • Optionally combine stdout and stderr
  • Optionally print the command's output if the command fails
  • The command can be formatted as a command-line string
  • The Command type can be cloned and its fields are public

Dependencies and features

  • log - this is an optional dependency. It can be disabled by turning off the logging feature:

    command-run = { version = "*", default-features = false }
    
  • os_pipe - this dependency is used to implement combine_output.

Example

// This will return an error if the command did not exit successfully
// (controlled with the `check` field).
let output = Command::with_args("echo", &["hello", "world"])
    .enable_capture()
    .run()?;
assert_eq!(output.stdout_string_lossy(), "hello world\n");

Dependencies

~0–7.5MB
~43K SLoC