Skip to content
Myr

command.rs

This file

Path

src/exec/command.rs

39 lines · 1.3 KiB · Rust

Last changed by

Add support for batch execution of commandkimsnjbefore adoption45d1b15

History of this file

Take it

Remove CommandTicket to avoid Vec allocationMatthias Reitingerbefore adoptionc18caaa

lines 1–9why, one step back
1// Copyright (c) 2017 fd developers
2// 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;

Unify execute_command across platformsMatthias Reitingerbefore adoption5784823

line 10why, one step back
10use std::io::Write;

Run latest version of rustfmtsharkdpbefore adoption6a9f16e

line 11why, one step back
11use std::process::Command;

Add support for batch execution of commandkimsnjbefore adoption45d1b15

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

Remove CommandTicket to avoid Vec allocationMatthias Reitingerbefore adoptionc18caaa

lines 13–14why, one step back
13
14/// Executes a command.

Add support for batch execution of commandkimsnjbefore adoption45d1b15

line 15why, one step back
15pub fn execute_command(mut cmd: Command, out_perm: &Mutex<()>) {

Remove CommandTicket to avoid Vec allocationMatthias Reitingerbefore adoptionc18caaa

line 16why, one step back
16 // Spawn the supplied command.

Unify execute_command across platformsMatthias Reitingerbefore adoption5784823

line 17why, one step back
17 let output = cmd.output();

Remove CommandTicket to avoid Vec allocationMatthias Reitingerbefore adoptionc18caaa

lines 18–22why, one step back
18
19 // 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 allowed

Unify execute_command across platformsMatthias Reitingerbefore adoption5784823

line 23why, one step back
23 // to write its outputs.

Remove CommandTicket to avoid Vec allocationMatthias Reitingerbefore adoptionc18caaa

lines 24–31why, one step back
24 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 }

Minor changes to improve readabilityJosh Leeb-du Toitbefore adoption8691ab4

line 32why, one step back
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);

Minor changes to improve readabilityJosh Leeb-du Toitbefore adoption8691ab4

line 34why, one step back
34 }

Update error message if command could not be foundsharkdpbefore adoption5ed7514

line 35why, one step back
35 Err(why) => {

Unify error messages, closes #342sharkdpbefore adoption81a27fa

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

Update error message if command could not be foundsharkdpbefore adoption5ed7514

line 37why, one step back
37 }

Remove CommandTicket to avoid Vec allocationMatthias Reitingerbefore adoptionc18caaa

lines 38–39why, one step back
38 }
39}