Trait command_group::tokio::AsyncCommandGroup
source · pub trait AsyncCommandGroup {
// Required method
fn group(&mut self) -> CommandGroupBuilder<'_, Command>;
// Provided methods
fn group_spawn(&mut self) -> Result<AsyncGroupChild> { ... }
fn group_output<'life0, 'async_trait>(
&'life0 mut self
) -> Pin<Box<dyn Future<Output = Result<Output>> + Send + 'async_trait>>
where Self: Send + 'async_trait,
'life0: 'async_trait { ... }
fn group_status<'life0, 'async_trait>(
&'life0 mut self
) -> Pin<Box<dyn Future<Output = Result<ExitStatus>> + Send + 'async_trait>>
where Self: Send + 'async_trait,
'life0: 'async_trait { ... }
}
Expand description
Extensions for Command
adding support for process groups.
This uses async_trait
for now to provide async methods as a trait.
Required Methods§
sourcefn group(&mut self) -> CommandGroupBuilder<'_, Command>
fn group(&mut self) -> CommandGroupBuilder<'_, Command>
Converts the implementor into a CommandGroupBuilder
, which can be used to
set flags that are not available on the Command
type.
Provided Methods§
sourcefn group_spawn(&mut self) -> Result<AsyncGroupChild>
fn group_spawn(&mut self) -> Result<AsyncGroupChild>
Executes the command as a child process group, returning a handle to it.
By default, stdin, stdout and stderr are inherited from the parent.
On Windows, this creates a job object instead of a POSIX process group.
Examples
Basic usage:
use tokio::process::Command;
use command_group::AsyncCommandGroup;
Command::new("ls")
.group_spawn()
.expect("ls command failed to start");
sourcefn group_output<'life0, 'async_trait>(
&'life0 mut self
) -> Pin<Box<dyn Future<Output = Result<Output>> + Send + 'async_trait>>where
Self: Send + 'async_trait,
'life0: 'async_trait,
fn group_output<'life0, 'async_trait>( &'life0 mut self ) -> Pin<Box<dyn Future<Output = Result<Output>> + Send + 'async_trait>>where Self: Send + 'async_trait, 'life0: 'async_trait,
Executes the command as a child process group, 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.
On Windows, this creates a job object instead of a POSIX process group.
Examples
use tokio::process::Command;
use std::io::{self, Write};
use command_group::AsyncCommandGroup;
let output = Command::new("/bin/cat")
.arg("file.txt")
.group_output()
.await
.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());
sourcefn group_status<'life0, 'async_trait>(
&'life0 mut self
) -> Pin<Box<dyn Future<Output = Result<ExitStatus>> + Send + 'async_trait>>where
Self: Send + 'async_trait,
'life0: 'async_trait,
fn group_status<'life0, 'async_trait>( &'life0 mut self ) -> Pin<Box<dyn Future<Output = Result<ExitStatus>> + Send + 'async_trait>>where Self: Send + 'async_trait, 'life0: 'async_trait,
Executes a command as a child process group, waiting for it to finish and collecting its status.
By default, stdin, stdout and stderr are inherited from the parent.
On Windows, this creates a job object instead of a POSIX process group.
Examples
use tokio::process::Command;
use command_group::AsyncCommandGroup;
let status = Command::new("/bin/cat")
.arg("file.txt")
.group_status()
.await
.expect("failed to execute process");
println!("process finished with: {}", status);
assert!(status.success());