Macro cmd_lib::spawn_with_output[][src]

spawn_with_output!() { /* proc-macro */ }
Expand description

Run commands with/without pipes as a child process, returning a handle to capture the final output

let mut procs = vec![];
for _ in 0..4 {
    let proc = spawn_with_output!(
        sudo bash -c "dd if=$file of=/dev/null bs=$block_size skip=$off count=$cnt 2>&1"
        | awk r#"/copied/{print $(NF-1) " " $NF}"#
    )?;
    procs.push(proc);
}

for (i, mut proc) in procs.into_iter().enumerate() {
    let bandwidth = proc.wait_fun_result()?;
    run_cmd!(info "thread $i bandwidth: $bandwidth MB/s")?;
}