Function unix_exec_output_catcher::fork_exec_and_catch[][src]

pub fn fork_exec_and_catch(
    executable: &str,
    args: Vec<&str>,
    strategy: OCatchStrategy
) -> Result<ProcessOutput, UECOError>
Expand description

Executes a program in a child process and returns the output of STDOUT and STDERR line by line in a vector. Be aware that this is blocking and static! So if your executable produces 1GB of output text, the data of the vectors of the returned structs is also 1GB in size. If the program doesn’t terminate, this function will neither.

This lib/function works fine for commands like “$ sysctl -a” or “$ ls -la”.

⚠️ Difference to std::process::Command 🚨 std::process::Command does the same in the standard library but with one exception: My library gives you access to stdout, stderr, and “stdcombined”. This way you get all output lines in the order they appeared. That’s the unique feature of this crate.

  • executable Path or name of executable without null (\0). Lookup in $PATH happens automatically.
  • args vector of args, each without null (\0). Remember that the first real arg starts at index 1. index 0 is usually the name of the executable. See: https://unix.stackexchange.com/questions/315812/why-does-argv-include-the-program-name
  • strategy Specify how accurate the "STDCOMBINED vecor is. See crate::OCatchStrategy for more information.