command.rs
This file
Path
src/exec/command.rs
41 lines · 1.2 KiB · Rust
Last changed by
Remove outdated license headers (not strictly required by Apache-2.0)sharkdpbefore adoption4274075
History of this fileTake it
The walk stopped after 200 commits: lines older than d81cf34 point at it.
fd is now officially in Debian (#345)Sylvestre Ledrubefore adoptiond81cf34
lines 1–3why, one step back1use std::io;2use std::io::Write;3use std::process::Command;Add support for batch execution of commandkimsnjbefore adoption45d1b15
line 4why, one step back4use std::sync::Mutex;fd is now officially in Debian (#345)Sylvestre Ledrubefore adoptiond81cf34
line 5why, one step back5Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
lines 6–7why, one step back6use crate::exit_codes::ExitCode;7fd is now officially in Debian (#345)Sylvestre Ledrubefore adoptiond81cf34
line 8why, one step back8/// Executes a command.Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
line 9why, one step back9pub fn execute_command(mut cmd: Command, out_perm: &Mutex<()>) -> ExitCode {fd is now officially in Debian (#345)Sylvestre Ledrubefore adoptiond81cf34
lines 10–24why, one step back10 // Spawn the supplied command.11 let output = cmd.output();1213 // Then wait for the command to exit, if it was spawned.14 match output {15 Ok(output) => {16 // While this lock is active, this thread will be the only thread allowed17 // to write its outputs.18 let _lock = out_perm.lock().unwrap();1920 let stdout = io::stdout();21 let stderr = io::stderr();2223 let _ = stdout.lock().write_all(&output.stdout);24 let _ = stderr.lock().write_all(&output.stderr);Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
lines 25–30why, one step back2526 if output.status.code() == Some(0) {27 ExitCode::Success28 } else {29 ExitCode::GeneralError30 }fd is now officially in Debian (#345)Sylvestre Ledrubefore adoptiond81cf34
lines 31–32why, one step back31 }32 Err(ref why) if why.kind() == io::ErrorKind::NotFound => {Unify error messages, closes #342sharkdpbefore adoption81a27fa
line 33why, one step back33 print_error!("Command not found: {:?}", cmd);Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
line 34why, one step back34 ExitCode::GeneralErrorfd is now officially in Debian (#345)Sylvestre Ledrubefore adoptiond81cf34
lines 35–36why, one step back35 }36 Err(why) => {Unify error messages, closes #342sharkdpbefore adoption81a27fa
line 37why, one step back37 print_error!("Problem while executing command: {}", why);Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
line 38why, one step back38 ExitCode::GeneralErrorfd is now officially in Debian (#345)Sylvestre Ledrubefore adoptiond81cf34
lines 39–41why, one step back39 }40 }41}