Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  runner.rs

  Sprache: Rust
 

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */


use std::io::{self, Read};
use std::process::{Command, Stdio};

use anyhow::{anyhow, Result};

pub(cratestruct CommandResult {
    pub(crate) exit_code: i32,
    pub(crate) output: String,
}

/// A simple trait to facilitate unit testing of functions that run commands.
pub(cratetrait CommandRunner {
    fn run(&self, cmd: Command) -> Result<CommandResult>;
}

pub(cratestruct RealRunner;

impl CommandRunner for RealRunner {
    fn run(&selfmut cmd: Command) -> Result<CommandResult> {
        // Pipe stdout and stderr to the same buffer. This ensures that the
        // output is exactly the same as would be seen in a shell, at the cost
        // of not separating stdout and stderr.
        let (mut stdout_r, stdout_w) = io::pipe()?;
        let stderr = stdout_w.try_clone()?;
        let mut child = cmd
            .stdout(Stdio::from(stdout_w))
            .stderr(Stdio::from(stderr))
            .spawn()?;

        // The `read_to_string` being called above won't return until an EOF
        // is found. That won't happen until the `stdout_w` we gave to `cmd`
        // is dropped. The cleanest way to do that is to drop `cmd` now that
        // we're done with it.
        drop(cmd);

        let mut output = String::new();
        stdout_r.read_to_string(&mut output)?;

        let exit_code = child
            .wait()?
            .code()
            .ok_or_else(|| anyhow!("process had no exit code"))?;

        return Ok(CommandResult {
            exit_code: exit_code,
            output: output,
        });
    }
}

Messung V0.5 in Prozent
C=83 H=95 G=88

¤ Dauer der Verarbeitung: 0.23 Sekunden  (vorverarbeitet am  2026-08-25) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Open Source Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Jenseits des Üblichen ....

Besucherstatistik

Besucherstatistik

Statistik
#Sources=277311
#Domains=752002