added example

This commit is contained in:
Maxime Van Hees
2025-04-02 14:41:50 +02:00
parent 288f17453b
commit 3f461334ec
7 changed files with 19 additions and 33 deletions

View File

@@ -76,7 +76,7 @@ pub struct CommandResult {
impl CommandResult {
/// Create a default failed result with an error message
fn error(message: &str) -> Self {
fn _error(message: &str) -> Self {
Self {
stdout: String::new(),
stderr: message.to_string(),
@@ -132,10 +132,6 @@ fn handle_child_output(mut child: Child, silent: bool) -> Result<CommandResult,
let stdout = child.stdout.take();
let stderr = child.stderr.take();
// Buffers for captured output
let mut captured_stdout = String::new();
let mut captured_stderr = String::new();
// Process stdout
let stdout_handle = if let Some(out) = stdout {
let reader = BufReader::new(out);
@@ -191,18 +187,18 @@ fn handle_child_output(mut child: Child, silent: bool) -> Result<CommandResult,
.map_err(|e| RunError::ChildProcessError(format!("Failed to wait on child process: {}", e)))?;
// Join our stdout thread if it exists
if let Some(handle) = stdout_handle {
captured_stdout = handle.join().unwrap_or_default();
let captured_stdout = if let Some(handle) = stdout_handle {
handle.join().unwrap_or_default()
} else {
captured_stdout = "Failed to capture stdout".to_string();
}
"Failed to capture stdout".to_string()
};
// Join our stderr thread if it exists
if let Some(handle) = stderr_handle {
captured_stderr = handle.join().unwrap_or_default();
let captured_stderr = if let Some(handle) = stderr_handle {
handle.join().unwrap_or_default()
} else {
captured_stderr = "Failed to capture stderr".to_string();
}
"Failed to capture stderr".to_string()
};
// Return the command result
Ok(CommandResult {