[][src]Struct pentacle::SealedCommand

pub struct SealedCommand { /* fields omitted */ }

A Command wrapper that spawns sealed memory-backed programs.

You can use the standard Command builder methods (such as spawn and CommandExt::exec) via Deref coercion.

Implementations

impl SealedCommand[src]

pub fn new<R: Read>(program: &mut R) -> Result<Self>[src]

Constructs a new Command for launching the program data in program as a sealed memory-backed file, with the same default configuration as Command::new.

The memory-backed file will close on execve(2) unless the program starts with #! (indicating that it is an interpreter script).

argv[0] of the program will default to the file descriptor path in procfs (for example, /proc/self/fd/3). CommandExt::arg0 can override this.

Errors

An error is returned if memfd_create(2) fails, the fcntl(2) F_ADD_SEALS command fails, or copying from program to the anonymous file fails.

Methods from Deref<Target = Command>

pub fn arg<S>(&mut self, arg: S) -> &mut Command where
    S: AsRef<OsStr>, 
1.0.0[src]

Adds an argument to pass to the program.

Only one argument can be passed per use. So instead of:

.arg("-C /path/to/repo")

usage would be:

.arg("-C")
.arg("/path/to/repo")

To pass multiple arguments see args.

Examples

Basic usage:

use std::process::Command;

Command::new("ls")
        .arg("-l")
        .arg("-a")
        .spawn()
        .expect("ls command failed to start");

pub fn args<I, S>(&mut self, args: I) -> &mut Command where
    I: IntoIterator<Item = S>,
    S: AsRef<OsStr>, 
1.0.0[src]

Adds multiple arguments to pass to the program.

To pass a single argument see arg.

Examples

Basic usage:

use std::process::Command;

Command::new("ls")
        .args(&["-l", "-a"])
        .spawn()
        .expect("ls command failed to start");

pub fn env<K, V>(&mut self, key: K, val: V) -> &mut Command where
    K: AsRef<OsStr>,
    V: AsRef<OsStr>, 
1.0.0[src]

Inserts or updates an environment variable mapping.

Note that environment variable names are case-insensitive (but case-preserving) on Windows, and case-sensitive on all other platforms.

Examples

Basic usage:

use std::process::Command;

Command::new("ls")
        .env("PATH", "/bin")
        .spawn()
        .expect("ls command failed to start");

pub fn envs<I, K, V>(&mut self, vars: I) -> &mut Command where
    I: IntoIterator<Item = (K, V)>,
    K: AsRef<OsStr>,
    V: AsRef<OsStr>, 
1.19.0[src]

Adds or updates multiple environment variable mappings.

Examples

Basic usage:

use std::process::{Command, Stdio};
use std::env;
use std::collections::HashMap;

let filtered_env : HashMap<String, String> =
    env::vars().filter(|&(ref k, _)|
        k == "TERM" || k == "TZ" || k == "LANG" || k == "PATH"
    ).collect();

Command::new("printenv")
        .stdin(Stdio::null())
        .stdout(Stdio::inherit())
        .env_clear()
        .envs(&filtered_env)
        .spawn()
        .expect("printenv failed to start");

pub fn env_remove<K>(&mut self, key: K) -> &mut Command where
    K: AsRef<OsStr>, 
1.0.0[src]

Removes an environment variable mapping.

Examples

Basic usage:

use std::process::Command;

Command::new("ls")
        .env_remove("PATH")
        .spawn()
        .expect("ls command failed to start");

pub fn env_clear(&mut self) -> &mut Command1.0.0[src]

Clears the entire environment map for the child process.

Examples

Basic usage:

use std::process::Command;

Command::new("ls")
        .env_clear()
        .spawn()
        .expect("ls command failed to start");

pub fn current_dir<P>(&mut self, dir: P) -> &mut Command where
    P: AsRef<Path>, 
1.0.0[src]

Sets the working directory for the child process.

Platform-specific behavior

If the program path is relative (e.g., "./script.sh"), it's ambiguous whether it should be interpreted relative to the parent's working directory or relative to current_dir. The behavior in this case is platform specific and unstable, and it's recommended to use canonicalize to get an absolute program path instead.

Examples

Basic usage:

use std::process::Command;

Command::new("ls")
        .current_dir("/bin")
        .spawn()
        .expect("ls command failed to start");

pub fn stdin<T>(&mut self, cfg: T) -> &mut Command where
    T: Into<Stdio>, 
1.0.0[src]

Configuration for the child process's standard input (stdin) handle.

Defaults to inherit when used with spawn or status, and defaults to piped when used with output.

Examples

Basic usage:

use std::process::{Command, Stdio};

Command::new("ls")
        .stdin(Stdio::null())
        .spawn()
        .expect("ls command failed to start");

pub fn stdout<T>(&mut self, cfg: T) -> &mut Command where
    T: Into<Stdio>, 
1.0.0[src]

Configuration for the child process's standard output (stdout) handle.

Defaults to inherit when used with spawn or status, and defaults to piped when used with output.

Examples

Basic usage:

use std::process::{Command, Stdio};

Command::new("ls")
        .stdout(Stdio::null())
        .spawn()
        .expect("ls command failed to start");

pub fn stderr<T>(&mut self, cfg: T) -> &mut Command where
    T: Into<Stdio>, 
1.0.0[src]

Configuration for the child process's standard error (stderr) handle.

Defaults to inherit when used with spawn or status, and defaults to piped when used with output.

Examples

Basic usage:

use std::process::{Command, Stdio};

Command::new("ls")
        .stderr(Stdio::null())
        .spawn()
        .expect("ls command failed to start");

pub fn spawn(&mut self) -> Result<Child, Error>1.0.0[src]

Executes the command as a child process, returning a handle to it.

By default, stdin, stdout and stderr are inherited from the parent.

Examples

Basic usage:

use std::process::Command;

Command::new("ls")
        .spawn()
        .expect("ls command failed to start");

pub fn output(&mut self) -> Result<Output, Error>1.0.0[src]

Executes the command as a child process, waiting for it to finish and collecting all of its output.

By default, stdout and stderr are captured (and used to provide the resulting output). Stdin is not inherited from the parent and any attempt by the child process to read from the stdin stream will result in the stream immediately closing.

Examples

This example panics
use std::process::Command;
use std::io::{self, Write};
let output = Command::new("/bin/cat")
                     .arg("file.txt")
                     .output()
                     .expect("failed to execute process");

println!("status: {}", output.status);
io::stdout().write_all(&output.stdout).unwrap();
io::stderr().write_all(&output.stderr).unwrap();

assert!(output.status.success());

pub fn status(&mut self) -> Result<ExitStatus, Error>1.0.0[src]

Executes a command as a child process, waiting for it to finish and collecting its exit status.

By default, stdin, stdout and stderr are inherited from the parent.

Examples

This example panics
use std::process::Command;

let status = Command::new("/bin/cat")
                     .arg("file.txt")
                     .status()
                     .expect("failed to execute process");

println!("process exited with: {}", status);

assert!(status.success());

Trait Implementations

impl Debug for SealedCommand[src]

impl Deref for SealedCommand[src]

type Target = Command

The resulting type after dereferencing.

impl DerefMut for SealedCommand[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.