Skip to main content

Command

Struct Command 

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

A process to spawn, as std::process::Command describes it.

Implementations§

Source§

impl Command

Source

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

A command for program, with its environment and working directory the process’s, and its standard streams inherited.

Source

pub fn arg(&mut self, arg: impl AsRef<OsStr>) -> &mut Self

Adds an argument.

Source

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

Adds arguments.

Source

pub fn env( &mut self, key: impl AsRef<OsStr>, value: impl AsRef<OsStr>, ) -> &mut Self

Sets an environment variable of the child.

Source

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

Sets environment variables of the child.

Source

pub fn env_remove(&mut self, key: impl AsRef<OsStr>) -> &mut Self

Takes an environment variable out of the child’s environment.

Source

pub fn env_clear(&mut self) -> &mut Self

Starts the child with no environment but what is set after.

Source

pub fn current_dir(&mut self, dir: impl AsRef<Path>) -> &mut Self

Sets the child’s working directory.

Source

pub fn stdin(&mut self, cfg: impl Into<Stdio>) -> &mut Self

Sets the child’s stdin.

Source

pub fn stdout(&mut self, cfg: impl Into<Stdio>) -> &mut Self

Sets the child’s stdout.

Source

pub fn stderr(&mut self, cfg: impl Into<Stdio>) -> &mut Self

Sets the child’s stderr.

Source

pub fn kill_on_drop(&mut self, kill: bool) -> &mut Self

Whether the child is ended, as Child::start_kill ends it, when its Child is dropped before it exits (default false: it runs on, and is still reaped once it exits).

use nuclei::process::Command;

let child = Command::new("sleep").arg("60").kill_on_drop(true).spawn()?;
drop(child); // the child is ended here
Source

pub fn get_kill_on_drop(&self) -> bool

Whether kill_on_drop is set.

Source

pub fn as_std(&self) -> &Command

The std command underneath, for what this one does not mirror.

Source

pub fn as_std_mut(&mut self) -> &mut Command

The std command underneath, to change.

Source

pub fn into_std(self) -> Command

The std command underneath, taken.

Source

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

Spawns the child. Its piped streams are async.

§Errors

When the child cannot start, or its pipes cannot be taken over.

Source

pub fn spawn_with( &mut self, with: impl FnOnce(&mut Command) -> Result<Child>, ) -> Result<Child>

Spawns the child through with, which starts it from the std command underneath: for a way to start a child this type does not mirror, such as a platform’s own spawn call with extra attributes. The child with returns is then this one’s, its piped streams async.

use nuclei::process::Command;

let mut child = Command::new("true").spawn_with(|std| std.spawn())?;
assert!(child.wait().await?.success());
§Errors

What with returns, and when the child’s pipes cannot be taken over.

Source

pub async fn status(&mut self) -> Result<ExitStatus>

Spawns the child and waits for its exit; its streams are inherited unless set.

§Errors

As for spawn and Child::wait.

Source

pub async fn output(&mut self) -> Result<Output>

Spawns the child with its stdout and stderr piped (and its stdin empty, unless set), and collects both until its exit.

§Errors

As for spawn and Child::wait_with_output.

Trait Implementations§

Source§

impl Debug for Command

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Command> for Command

Source§

fn from(std: Command) -> Self

Converts to this type from the input type.

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.

§

impl<T> MaybeSend for T
where T: Send + ?Sized,

Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.