From f2ec93e0f2aa71e637bf00735e9359bffa3029a0 Mon Sep 17 00:00:00 2001 From: aprilthepink Date: Sat, 22 Feb 2025 00:29:35 +0100 Subject: [PATCH] execute shell cmd --- src/main.rs | 3 +++ src/pman.rs | 15 +++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2aa4dfb..724af6f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -76,6 +76,9 @@ async fn main() { } Commands::Devtest => { + PMAN_SENDER.get().unwrap().send(ProcessCommand::SpawnShellCmd { + cmd: "sleep 100 && echo hello meow".to_string(), + }).await.expect("TODO: panic message"); tokio::select! { _ = signal::ctrl_c() => { info!("Ctrl-c received"); diff --git a/src/pman.rs b/src/pman.rs index 9565d28..d1849f4 100644 --- a/src/pman.rs +++ b/src/pman.rs @@ -59,11 +59,17 @@ impl ProcessManager { } } fn spawn_bash_command(&mut self, command: String) { - let cmd = Command::new("bash") + debug!("Spawning bash cmd {}", command); + let mut cmd = Command::new("bash") .arg("-c") .arg(command) .spawn().unwrap(); - self.processes.push(cmd); + + let _ = tokio::spawn(async move { + cmd.wait().await; + }); + // Doesnt make sense to list cmd commands + // self.processes.push(cmd); } fn spawn_cmd_command(&mut self, command: String) {} fn spawn_zsh_command(&mut self, command: String) {} @@ -71,7 +77,9 @@ impl ProcessManager { let opt = rx.recv().await; if let Some(message) = opt { match message { - ProcessCommand::SpawnShellCmd { cmd } => {} + ProcessCommand::SpawnShellCmd { cmd } => { + self.spawn_shell_command(cmd); + } ProcessCommand::Shutdown => { info!("Close command"); anyhow::bail!("Close command"); @@ -84,7 +92,6 @@ impl ProcessManager { } async fn alive_check(&mut self) -> Result<()> { for process in &mut self.processes { - process.stdout } Ok(()) }