Skip to content
Myr

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 file

Take 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 back
1use std::io;
2use std::io::Write;3use std::process::Command;

Add support for batch execution of commandkimsnjbefore adoption45d1b15

line 4why, one step back
4use std::sync::Mutex;

fd is now officially in Debian (#345)Sylvestre Ledrubefore adoptiond81cf34

line 5why, one step back
5

Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd

lines 6–7why, one step back
6use crate::exit_codes::ExitCode;
7

fd is now officially in Debian (#345)Sylvestre Ledrubefore adoptiond81cf34

line 8why, one step back
8/// Executes a command.

Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd

line 9why, one step back
9pub 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 back
10 // 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 back
25
26 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 back
31 }
32 Err(ref why) if why.kind() == io::ErrorKind::NotFound => {

Unify error messages, closes #342sharkdpbefore adoption81a27fa

line 33why, one step back
33 print_error!("Command not found: {:?}", cmd);

Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd

line 34why, one step back
34 ExitCode::GeneralError

fd is now officially in Debian (#345)Sylvestre Ledrubefore adoptiond81cf34

lines 35–36why, one step back
35 }
36 Err(why) => {

Unify error messages, closes #342sharkdpbefore adoption81a27fa

line 37why, one step back
37 print_error!("Problem while executing command: {}", why);

Expose exit status from `--exec-batch <cmd>`sharkdpbefore adoptiona0505bd

line 38why, one step back
38 ExitCode::GeneralError

fd is now officially in Debian (#345)Sylvestre Ledrubefore adoptiond81cf34

lines 39–41why, one step back
39 }
40 }41}