pub struct Command { /* private fields */ }Expand description
A process to spawn, as std::process::Command describes it.
Implementations§
Source§impl Command
impl Command
Sourcepub fn new(program: impl AsRef<OsStr>) -> Self
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.
Sourcepub fn env(
&mut self,
key: impl AsRef<OsStr>,
value: impl AsRef<OsStr>,
) -> &mut Self
pub fn env( &mut self, key: impl AsRef<OsStr>, value: impl AsRef<OsStr>, ) -> &mut Self
Sets an environment variable of the child.
Sourcepub fn env_remove(&mut self, key: impl AsRef<OsStr>) -> &mut Self
pub fn env_remove(&mut self, key: impl AsRef<OsStr>) -> &mut Self
Takes an environment variable out of the child’s environment.
Sourcepub fn env_clear(&mut self) -> &mut Self
pub fn env_clear(&mut self) -> &mut Self
Starts the child with no environment but what is set after.
Sourcepub fn current_dir(&mut self, dir: impl AsRef<Path>) -> &mut Self
pub fn current_dir(&mut self, dir: impl AsRef<Path>) -> &mut Self
Sets the child’s working directory.
Sourcepub fn kill_on_drop(&mut self, kill: bool) -> &mut Self
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 hereSourcepub fn get_kill_on_drop(&self) -> bool
pub fn get_kill_on_drop(&self) -> bool
Whether kill_on_drop is set.
Sourcepub fn as_std(&self) -> &Command
pub fn as_std(&self) -> &Command
The std command underneath, for what this one does not mirror.
Sourcepub fn as_std_mut(&mut self) -> &mut Command
pub fn as_std_mut(&mut self) -> &mut Command
The std command underneath, to change.
Sourcepub fn spawn(&mut self) -> Result<Child>
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.
Sourcepub fn spawn_with(
&mut self,
with: impl FnOnce(&mut Command) -> Result<Child>,
) -> Result<Child>
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.
Sourcepub async fn status(&mut self) -> Result<ExitStatus>
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.