Skip to main content

spawn_process

Function spawn_process 

Source
pub fn spawn_process(cmd: &str, args: Vec<String>) -> Result<Child, Error>
Expand description

Spawn a new async process with piped stdout and stderr.

Launches a subprocess with the given command and arguments using tokio. Both stdout and stderr are piped and can be accessed via the returned Child.

§Arguments

  • cmd - Command to execute
  • args - Command line arguments

§Returns

Returns a Result<Child, io::Error> - the spawned tokio process or an error.

§Examples

use ej_io::process::spawn_process;

#[tokio::main]
async fn main() {
    let mut child = spawn_process("echo", vec!["Hello".to_string()]).unwrap();
    let output = child.stdout.take().unwrap();
}