command.rs
This file
Path
src/exec/command.rs
56 lines · 1.6 KiB · Rust
Last changed by
Just trying some things out, initial functionalityMax Trianobefore adoption0f0fa76
History of this fileTake it
The walk stopped after 200 commits: lines older than 53557ef point at it.
Clean up include ordersharkdpbefore adoption53557ef
lines 1–11why, one step back1use std::io;2use std::io::Write;3use std::process::Command;4use std::sync::Mutex;56use crate::error::print_error;7use crate::exit_codes::ExitCode;89/// Executes a command.10pub fn execute_command(mut cmd: Command, out_perm: &Mutex<()>) -> ExitCode {11 // Spawn the supplied command.Just trying some things out, initial functionalityMax Trianobefore adoption0f0fa76
lines 12–24why, one step back12 /* let output = cmd.output(); */13 // This sort of works:14 let child = cmd.spawn().expect("failed to wait on child");15 let output = child16 .wait_with_output()17 .expect("failed to wait on child"); 18 ExitCode::Success19 /* let child_handle = cmd.spawn();20 match child_handle {21 Ok(output) => {22 let exit_code = output.wait();23 }24 Err() => {Clean up include ordersharkdpbefore adoption53557ef
line 25why, one step back25Just trying some things out, initial functionalityMax Trianobefore adoption0f0fa76
lines 26–27why, one step back26 }27 } */Clean up include ordersharkdpbefore adoption53557ef
line 28why, one step back28 // Then wait for the command to exit, if it was spawned.Just trying some things out, initial functionalityMax Trianobefore adoption0f0fa76
line 29why, one step back29 /* match output {Clean up include ordersharkdpbefore adoption53557ef
lines 30–37why, one step back30 Ok(output) => {31 // While this lock is active, this thread will be the only thread allowed32 // to write its outputs.33 let _lock = out_perm.lock().unwrap();3435 let stdout = io::stdout();36 let stderr = io::stderr();37Just trying some things out, initial functionalityMax Trianobefore adoption0f0fa76
lines 38–39why, one step back38 //let _ = stdout.lock().write_all(&output.stdout);39 //let _ = stderr.lock().write_all(&output.stderr);Clean up include ordersharkdpbefore adoption53557ef
lines 40–54why, one step back4041 if output.status.code() == Some(0) {42 ExitCode::Success43 } else {44 ExitCode::GeneralError45 }46 }47 Err(ref why) if why.kind() == io::ErrorKind::NotFound => {48 print_error(format!("Command not found: {:?}", cmd));49 ExitCode::GeneralError50 }51 Err(why) => {52 print_error(format!("Problem while executing command: {}", why));53 ExitCode::GeneralError54 }Just trying some things out, initial functionalityMax Trianobefore adoption0f0fa76
line 55why, one step back55 } */Clean up include ordersharkdpbefore adoption53557ef
line 56why, one step back56}