cmd-utils 0.3.1

rust Command utility traits, pipe commands
Documentation
  • Coverage
  • 66.67%
    16 out of 24 items documented1 out of 1 items with examples
  • Size
  • Source code size: 21.32 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.29 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 12s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • steven89/cmd-utils-rs
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • steven89

Crates.io Docs.rs

Cmd Utils

Safe Rust Command utility traits

  • run command (spawn & wait wrapper)
  • pipe commands
  • output to file (spawn & wait & outuput to file wrapper)

CmdRun trait

use std::process::Command;
use cmd_utils::CmdRun;

// `spawn` the command and `wait` for child process to end
// note that `run` does not return the command output, just Ok(())
// but you can redirect stdout & stderr where you want
Command::new("test")
    // .stdout(cfg)
    // .stderr(cfg)
    .args(["-n", "a"])
    .run()
    .unwrap();

example available:

cargo run --example cmd_run

CmdPipe trait

use std::process::Command;
use std::str;
use cmd_utils::CmdPipe;

// pipe echo & wc commands
// equivalent to bash: echo test | wc -c
let mut echo = Command::new("echo");
let mut wc = Command::new("wc");
let output = echo.arg("test")
    .pipe(&mut wc.arg("-c"))
    .unwrap();
let res = str::from_utf8(&output.stdout).unwrap();
println!("pipe result: {}", &res);

example available:

cargo run --example cmd_pipe

CmdToFile trait

use std::fs::File;
use std::process::Command;
use cmd_utils::CmdToFile;

let stdout = File::create("my_file.stdout").unwrap();
let stderr = File::create("my_file.stderr").unwrap();
let mut cmd = Command::new("echo");
// writes stdout to file
cmd.arg("test").to_file(stdout, Some(stderr));

example available:

cargo run --example cmd_to_file