mirror of
https://github.com/TECHNOFAB11/tmux-copyrat.git
synced 2025-12-13 08:30:07 +01:00
refactor: refactor
This commit is contained in:
parent
623c66cbba
commit
791aaadd49
10 changed files with 655 additions and 468 deletions
21
src/process.rs
Normal file
21
src/process.rs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
use std::process::Command;
|
||||
|
||||
use crate::error::ParseError;
|
||||
|
||||
/// Execute an arbitrary Unix command and return the stdout as a `String` if
|
||||
/// successful.
|
||||
pub fn execute(command: &str, args: &Vec<&str>) -> Result<String, ParseError> {
|
||||
let output = Command::new(command).args(args).output()?;
|
||||
|
||||
if !output.status.success() {
|
||||
let msg = String::from_utf8_lossy(&output.stderr);
|
||||
return Err(ParseError::ProcessFailure(format!(
|
||||
"Process failure: {} {}, error {}",
|
||||
command,
|
||||
args.join(" "),
|
||||
msg
|
||||
)));
|
||||
}
|
||||
|
||||
Ok(String::from_utf8_lossy(&output.stdout).to_string())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue