Skip to main content

Command

Struct Command 

Source
pub struct Command { /* private fields */ }
Expand description

A sandboxed process builder, providing fine-grained control over how a new process should be spawned.

This mirrors the API of std::process::Command but adds the ability to apply a sandbox policy that restricts filesystem access.

§Example

use std::path::Path;
use sandbox_run::{Command, Sandbox, ProtectSystem};

let sandbox = Sandbox::new()
    .protect_system(ProtectSystem::Strict)
    .read_write_paths([Path::new("/tmp")])
    .build()
    .unwrap();

let output = Command::new("ls")
    .arg("/usr")
    .sandbox(sandbox)
    .output()
    .expect("failed to execute process");

Implementations§

Source§

impl Command

Source

pub fn new<S: AsRef<OsStr>>(program: S) -> Self

Constructs a new Command for launching the program at path program.

Source

pub fn arg<S: AsRef<OsStr>>(self, arg: S) -> Self

Adds an argument to pass to the program.

Source

pub fn args<I, S>(self, args: I) -> Self
where I: IntoIterator<Item = S>, S: AsRef<OsStr>,

Adds multiple arguments to pass to the program.

Source

pub fn env<K, V>(self, key: K, val: V) -> Self
where K: AsRef<OsStr>, V: AsRef<OsStr>,

Inserts or updates an environment variable mapping.

Source

pub fn envs<I, K, V>(self, vars: I) -> Self
where I: IntoIterator<Item = (K, V)>, K: AsRef<OsStr>, V: AsRef<OsStr>,

Adds or updates multiple environment variable mappings.

Source

pub fn env_remove<K: AsRef<OsStr>>(self, key: K) -> Self

Removes an environment variable mapping.

Source

pub fn env_clear(self) -> Self

Clears the entire environment map for the child process.

Source

pub fn current_dir<P: AsRef<Path>>(self, dir: P) -> Self

Sets the working directory for the child process.

Source

pub fn stdin<T: Into<Stdio>>(self, cfg: T) -> Self

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

Source

pub fn stdout<T: Into<Stdio>>(self, cfg: T) -> Self

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

Source

pub fn stderr<T: Into<Stdio>>(self, cfg: T) -> Self

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

Source

pub fn sandbox(self, policy: SandboxPolicy) -> Self

Apply a sandbox policy to this command.

The sandbox will be applied to the child process after fork but before exec, restricting the process according to the policy.

Source

pub fn spawn(self) -> Result<Child>

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

Source

pub fn output(self) -> Result<Output>

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

Source

pub fn status(self) -> Result<ExitStatus>

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

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.