elemental_core/launcher/
process.rs1use tokio::process::{Child, Command};
2
3use super::{
4 command::LaunchCommand,
5 error::{Error, Result},
6};
7
8pub fn spawn_command(command: LaunchCommand) -> Result<Child> {
9 let program = command.program();
10 if program.as_os_str().is_empty() {
11 return Err(Error::EmptyExecutable);
12 }
13
14 let mut child = Command::new(&program);
15 child.args(command.arguments());
16
17 if let Some(cwd) = &command.cwd {
18 child.current_dir(cwd);
19 }
20
21 for (key, value) in &command.env {
22 child.env(key, value);
23 }
24
25 child
26 .spawn()
27 .map_err(|source| Error::Spawn { program, source })
28}