[][src]Function shellfn_core::execute_parse_result

pub fn execute_parse_result<T, TArg, TEnvKey, TEnvVal, TError>(
    cmd: impl AsRef<OsStr>,
    args: impl IntoIterator<Item = TArg>,
    envs: impl IntoIterator<Item = (TEnvKey, TEnvVal)>
) -> Result<T, TError> where
    T: FromStr,
    TArg: AsRef<OsStr>,
    TEnvKey: AsRef<OsStr>,
    TEnvVal: AsRef<OsStr>,
    <T as FromStr>::Err: StdError,
    TError: From<Error<<T as FromStr>::Err>>, 

Executes command with args and environment variables, parses output

  • On invalid command: return error
  • On error exit code: return error
  • On parsing failure: return error
  • Possible errors: ProcessNotSpawned, WaitFailed, ProcessFailed, NonUtf8Stdout, ParsingError

Designed for

use shellfn::shell;
use std::error::Error;

#[shell]
fn command() -> Result<u32, Box<Error>> {
    "echo -n 42"
}

assert_eq!(42, command().unwrap())