Skip to content

Commit

Permalink
fix: bail on execute command returns not 0
Browse files Browse the repository at this point in the history
  • Loading branch information
cnwangjie committed Jan 25, 2021
1 parent b6d1ae0 commit b284f93
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::Result;
use anyhow::{Result, bail};
use percent_encoding::{utf8_percent_encode, AsciiSet, CONTROLS};
use std::ffi::OsStr;
use std::process::Command;
Expand All @@ -13,8 +13,15 @@ pub fn spawn(command: &str) -> Result<String> {
let mut parts = command.split(' ');
let program = parts.next().unwrap();
let args: Vec<&OsStr> = parts.map(OsStr::new).collect();
let mut cmd = Command::new(program);

let buf = Command::new(program).args(args).output()?.stdout;
cmd.args(args);

if !cmd.status()?.success() {
bail!(format!("Failed to execute {}", command))
}

let buf = cmd.output()?.stdout;

let result = String::from_utf8(buf)?;

Expand Down

0 comments on commit b284f93

Please sign in to comment.