command.rs
This file
Path
src/exec/command.rs
40 lines · 1.3 KiB · Rust
Last changed by
Unify execute_command across platformsMatthias Reitingerbefore adoption5784823
History of this fileTake it
Remove CommandTicket to avoid Vec allocationMatthias Reitingerbefore adoptionc18caaa
lines 1–11why, 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::process::Command;10use std::sync::{Arc, Mutex};11use std::io;Unify execute_command across platformsMatthias Reitingerbefore adoption5784823
line 12why, one step back12use std::io::Write;Remove CommandTicket to avoid Vec allocationMatthias Reitingerbefore adoptionc18caaa
lines 13–16why, one step back1314/// Executes a command.15pub fn execute_command(mut cmd: Command, out_perm: Arc<Mutex<()>>) {16 // Spawn the supplied command.Unify execute_command across platformsMatthias Reitingerbefore adoption5784823
line 17why, one step back17 let output = cmd.output();Remove CommandTicket to avoid Vec allocationMatthias Reitingerbefore adoptionc18caaa
lines 18–22why, one step back1819 // Then wait for the command to exit, if it was spawned.20 match output {21 Ok(output) => {22 // While this lock is active, this thread will be the only thread allowedUnify execute_command across platformsMatthias Reitingerbefore adoption5784823
line 23why, one step back23 // to write its outputs.Remove CommandTicket to avoid Vec allocationMatthias Reitingerbefore adoptionc18caaa
lines 24–31why, one step back24 let _lock = out_perm.lock().unwrap();2526 let stdout = io::stdout();27 let stderr = io::stderr();2829 let _ = stdout.lock().write_all(&output.stdout);30 let _ = stderr.lock().write_all(&output.stderr);31 }Update error message if command could not be foundsharkdpbefore adoption5ed7514
lines 32–38why, one step back32 Err(why) => {33 if why.kind() == io::ErrorKind::NotFound {34 eprintln!("fd: execution error: command not found");35 } else {36 eprintln!("fd: execution error: {}", why);37 }38 }Remove CommandTicket to avoid Vec allocationMatthias Reitingerbefore adoptionc18caaa
lines 39–40why, one step back39 }40}