Function run_funcs

Source
pub fn run_funcs(
    command: &mut Command,
    stdout_func: impl FnOnce(Lines<BufReader<ChildStdout>>) + Send + 'static,
    stderr_func: impl FnOnce(Lines<BufReader<ChildStderr>>) + Send + 'static,
) -> CmdOutput
Expand description

Runs a command while simultaneously running a provided Fn as the command prints line-by-line

The CmdOutput will be None; this does not handle the lines - if you need them, use run or run_funcs_with_lines

Example:

use better_commands::run_funcs;
use better_commands::Line;
use std::process::Command;
run_funcs(&mut Command::new("echo").arg("hi"), {
    |stdout_lines| {
        for line in stdout_lines {
            /* send line to database */
            }
        }
    },
    {
    |stderr_lines| {
        // this code is for stderr and won't run because echo won't print anything to stderr
    }
});