Skip to content

Commit

Permalink
Merge pull request #40 from afh/stream-launch-output
Browse files Browse the repository at this point in the history
Stream output from launched command
  • Loading branch information
humblepenguinn authored Feb 17, 2024
2 parents 05a0211 + d5a17d8 commit ea49184
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/bin/envio/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,16 +354,29 @@ impl Command {
return;
};


let output = std::process::Command::new(program)
.envs(profile.envs)
.args(args)
.output()
.stdout(std::process::Stdio::inherit())
.stderr(std::process::Stdio::inherit())
.spawn()
.expect("Failed to execute command");

if output.stderr.is_empty() {
println!("{}", String::from_utf8(output.stdout).unwrap());
} else {
println!("{}", String::from_utf8(output.stderr).unwrap());

let status = match cmd.wait() {
Ok(s) => s,
Err(e) => {
println!("{}: {}", "Error".red(), e);
exit(1);
}
};

match status.code() {
Some(code) => std::process::exit(code),
None => {
println!("{}: Child process terminated by signal", "Error".red());
std::process::exit(1);
}
}
}

Expand Down

0 comments on commit ea49184

Please sign in to comment.