Trait System

Source
pub trait System<T> {
    // Required method
    fn system(command: &str) -> T;
}
Expand description

Trait to allow for the creation of objects representing a shell commands.

Required Methods§

Source

fn system(command: &str) -> T

Constructs a new T that runs the given shell command when executed.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl System<Command> for Command

Source§

fn system(command: &str) -> Command

Construct a new Command that runs the given system command when executed.

See Command::new for the default configuration.

§Example
use std::process::Command;

use system::System;

fn main() {
    let out = Command::system("echo Hello, world!")
        .output()
        .expect("Failed to run command.");
    let stdout = String::from_utf8_lossy(&out.stdout);

    #[cfg(target_os = "windows")]
    assert_eq!(stdout, "Hello, world!\r\n");

    #[cfg(not(target_os = "windows"))]
    assert_eq!(stdout, "Hello, world!\n");
}

Implementors§