command.rs
This file
Path
src/exec/command.rs
49 lines · 1.6 KiB · Rust
Last changed by
Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
History of this fileTake it
The walk stopped after 200 commits: lines older than 88fb9d7 point at it.
Run updated version of rustfmtsharkdpbefore adoption88fb9d7
lines 1–10why, one step back1// Copyright (c) 2017 fd developers2// Licensed under the Apache License, Version 2.03// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0>4// or the MIT license <LICENSE-MIT or http://opensource.org/licenses/MIT>,5// at your option. All files in the project carrying such6// notice may not be copied, modified, or distributed except7// according to those terms.89use std::io;10use std::io::Write;Run latest version of rustfmtsharkdpbefore adoption6a9f16e
line 11why, one step back11use std::process::Command;Add support for batch execution of commandkimsnjbefore adoption45d1b15
line 12why, one step back12use std::sync::Mutex;Run updated version of rustfmtsharkdpbefore adoption88fb9d7
line 13why, one step back13Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
lines 14–15why, one step back14use crate::exit_codes::ExitCode;15Run updated version of rustfmtsharkdpbefore adoption88fb9d7
line 16why, one step back16/// Executes a command.Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
line 17why, one step back17pub fn execute_command(mut cmd: Command, out_perm: &Mutex<()>) -> ExitCode {Run updated version of rustfmtsharkdpbefore adoption88fb9d7
lines 18–32why, one step back18 // Spawn the supplied command.19 let output = cmd.output();2021 // Then wait for the command to exit, if it was spawned.22 match output {23 Ok(output) => {24 // While this lock is active, this thread will be the only thread allowed25 // to write its outputs.26 let _lock = out_perm.lock().unwrap();2728 let stdout = io::stdout();29 let stderr = io::stderr();3031 let _ = stdout.lock().write_all(&output.stdout);32 let _ = stderr.lock().write_all(&output.stderr);Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
lines 33–38why, one step back3334 if output.status.code() == Some(0) {35 ExitCode::Success36 } else {37 ExitCode::GeneralError38 }Run updated version of rustfmtsharkdpbefore adoption88fb9d7
line 39why, one step back39 }Minor changes to improve readabilityJosh Leeb-du Toitbefore adoption8691ab4
line 40why, one step back40 Err(ref why) if why.kind() == io::ErrorKind::NotFound => {Unify error messages, closes #342sharkdpbefore adoption81a27fa
line 41why, one step back41 print_error!("Command not found: {:?}", cmd);Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
line 42why, one step back42 ExitCode::GeneralErrorMinor changes to improve readabilityJosh Leeb-du Toitbefore adoption8691ab4
line 43why, one step back43 }Run updated version of rustfmtsharkdpbefore adoption88fb9d7
line 44why, one step back44 Err(why) => {Unify error messages, closes #342sharkdpbefore adoption81a27fa
line 45why, one step back45 print_error!("Problem while executing command: {}", why);Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd
line 46why, one step back46 ExitCode::GeneralErrorRun updated version of rustfmtsharkdpbefore adoption88fb9d7
lines 47–49why, one step back47 }48 }49}