diff options
| author | datdenkikniet <jcdra1@gmail.com> | 2023-04-15 00:09:50 +0200 |
|---|---|---|
| committer | datdenkikniet <jcdra1@gmail.com> | 2023-04-15 00:09:50 +0200 |
| commit | fa92d8abe7810c8a32a37be49f162b795c226f4d (patch) | |
| tree | 2cc6ccb915b6e864c33a4321f0d51baf10d97865 /xtask/src/command.rs | |
| parent | f741475a3f552585f789b3b2b9c622b090e72057 (diff) | |
Add some QoL to run_command
Diffstat (limited to 'xtask/src/command.rs')
| -rw-r--r-- | xtask/src/command.rs | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/xtask/src/command.rs b/xtask/src/command.rs index 6e91a52..8a2e99b 100644 --- a/xtask/src/command.rs +++ b/xtask/src/command.rs @@ -1,7 +1,10 @@ use crate::{debug, ExtraArguments, Package, RunResult, TestRunError}; use core::fmt; -use os_pipe::pipe; -use std::{fs::File, io::Read, process::Command}; +use std::{ + fs::File, + io::Read, + process::{Command, Stdio}, +}; #[allow(dead_code)] #[derive(Debug, Clone, Copy, PartialEq)] @@ -412,26 +415,26 @@ impl fmt::Display for BuildMode { } pub fn run_command(command: &CargoCommand) -> anyhow::Result<RunResult> { - let (mut reader, writer) = pipe()?; - let (mut error_reader, error_writer) = pipe()?; - debug!("👟 {} {}", command.executable(), command.args().join(" ")); + let command_display = command.executable(); + let args = command.args(); - let mut handle = Command::new(command.executable()) - .args(command.args()) - .stdout(writer) - .stderr(error_writer) - .spawn()?; + let full_command = format!("\"{command_display}\" {}", args.join(" ")); + + debug!("👟 {full_command}"); - // retrieve output and clean up - let mut stdout = String::new(); - reader.read_to_string(&mut stdout)?; - let exit_status = handle.wait()?; + let result = Command::new(command.executable()) + .args(command.args()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output()?; - let mut stderr = String::new(); - error_reader.read_to_string(&mut stderr)?; + let exit_status = result.status; + let stderr = String::from_utf8(result.stderr).unwrap_or("Not displayable".into()); + let stdout = String::from_utf8(result.stdout).unwrap_or("Not displayable".into()); Ok(RunResult { exit_status, + full_command, stdout, stderr, }) |
