#cmd #process #child-process #bash #shell #log-error #log-level

build devx-cmd

Convenience wrapper over std::process::Command for xtask crates

6 releases (breaking)

0.5.0 Jun 2, 2021
0.4.0 May 28, 2021
0.3.1 Sep 22, 2020
0.3.0 Aug 29, 2020
0.1.0 Aug 16, 2020

#427 in Build Utils

Download history 3708/week @ 2024-10-09 4961/week @ 2024-10-16 5610/week @ 2024-10-23 4504/week @ 2024-10-30 3990/week @ 2024-11-06 4111/week @ 2024-11-13 3675/week @ 2024-11-20 2820/week @ 2024-11-27 4710/week @ 2024-12-04 3286/week @ 2024-12-11 2146/week @ 2024-12-18 608/week @ 2024-12-25 2118/week @ 2025-01-01 4168/week @ 2025-01-08 3595/week @ 2025-01-15 4835/week @ 2025-01-22

14,758 downloads per month
Used in devx-pre-commit

MIT/Apache

27KB
412 lines

devx-cmd

devx-cmd provides more convenient primitives for spawning child processes than std::process targeted for use in development scripts specifically.

See the crate-level docs for more info.


lib.rs:

devx-cmd provides more convenient primitives for spawning child processes than std::process targeted for use in development scripts specifically.

The main entities of the crate are [Cmd] (builder for executable commands), and Child (represents a spawned process).

There are also some convenient macros to reduce boilerplate. Here is the basic usage example:

use devx_cmd::{read, run, cmd, Cmd};

// Initialize some low-overhead logger implementation for the `log` crate
simple_logger::SimpleLogger::new().init().unwrap();

// Run the program, logging the invocation via [`log`] crate and waiting until it finishes
// This is used only for side-effects.
// Note that if the process ends with a non-zero status code, this will return an error.
run!("ls", "-la")?;

// Same as `run!()`, but captures the stdout and returns it as a `String`
// there is also a `read_bytes!()` for non-utf8 sequences
let output = read!("echo", "foo")?;
assert_eq!(output.trim(), "foo");

let mut cmd = cmd!("rustfmt");
cmd
    // Set `trace` level for logging command invocation and output (`debug` by default)
    .log_cmd(log::Level::Trace)
    // Don't log error if the command fails
    .log_err(None)
    .stdin("fn foo () -> u32 {42}\n");

// Spawn without waiting for its completion, but capturing the stdout
let mut child = cmd.spawn_piped()?;

// Read output line-by-line
let first_line = child.stdout_lines().next().unwrap();

assert_eq!(first_line.trim(), "fn foo() -> u32 {");

// Dropping the child process `kill()`s it (and ignores the `Result`)
// Use `.wait()/.read()` to wait until its completion.
drop(child);

Dependencies

~87KB

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy