/// Execute the command and capture the output.
Execute the command and capture the output.
Execute the command and capture the output .
pub fn execute(&self) -> UtilityCommandResult<Vec<u8>> {
        let mut cmd = StdCommand::new(self.program.clone());
        cmd.args(self.args.clone());
        cmd.stdin(Stdio::piped());
        cmd.stderr(Stdio::piped());
        cmd.stdout(Stdio::piped());
        let map_to_err = |e: std::io::Error| {
            UtilityCommandError::IoError(format!("Error while running '{}': {}", self, e))
        };
        let mut child = cmd.spawn().map_err(map_to_err)?;
        let mut stdin = match child.stdin.take() {
            Some(v) => v,
            None => {
                return Err(UtilityCommandError::IoError(
                    "Could not fetch stdin of child process.".to_string(),
                ))
            }
        };
        stdin.write_all(self.input.as_slice()).map_err(map_to_err)?;
        stdin.flush().map_err(map_to_err)?;
        drop(stdin);
        let output = child.wait_with_output().map_err(map_to_err)?;
        if output.status.success() {
            Ok(output.stdout)
        } else {
            Err(UtilityCommandError::Failed(
                format!(
                    "Error while running '{}': {}",
                    self,
                    std::str::from_utf8(output.stderr.as_slice())
                        .unwrap()
                        .to_string()
                ),
                output.status,
            ))
        }
    }
pub fn execute ( & self ) -> UtilityCommandResult < Vec < u8 > > { let mut cmd = StdCommand :: new ( self . program . clone ( ) ) ; cmd . args ( self . args . clone ( ) ) ; cmd . stdin ( Stdio :: piped ( ) ) ; cmd . stderr ( Stdio :: piped ( ) ) ; cmd . stdout ( Stdio :: piped ( ) ) ; let map_to_err = | e : std :: io :: Error | { UtilityCommandError :: IoError ( format ! ( " " self e ) ) } ; let mut child = cmd . spawn ( ) . map_err ( map_to_err ) ? ; let mut stdin = match child . stdin . take ( ) { Some ( v ) => v , None => { return Err ( UtilityCommandError :: IoError ( " " . to_string ( ) , ) ) } } ; stdin . write_all ( self . input . as_slice ( ) ) . map_err ( map_to_err ) ? ; stdin . flush ( ) . map_err ( map_to_err ) ? ; drop ( stdin ) ; let output = child . wait_with_output ( ) . map_err ( map_to_err ) ? ; if output . status . success ( ) { Ok ( output . stdout ) } else { Err ( UtilityCommandError :: Failed ( format ! ( " " self std str from_utf8 ( output stderr as_slice ( ) ) unwrap ( ) to_string ( ) ) , output . status , ) ) } }
Execute the command and capture the output.
Execute the command and capture the output .
&self