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

Run commands with/without pipes as a child process, returning FunChildren result.

let mut procs = vec![];
for _ in 0..4 {
    let proc = spawn_with_output!(
        sudo bash -c "dd if=/dev/nvmen0 of=/dev/null bs=4096 skip=0 count=1024 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_with_output()?;
    info!("thread {i} bandwidth: {bandwidth} MB/s");
}