From 4404ab4d5dec2aeeb535d1725dbeb1a2048ff6ed Mon Sep 17 00:00:00 2001 From: elkowar <5300871+elkowar@users.noreply.github.com> Date: Sat, 26 Dec 2020 12:59:59 +0100 Subject: [PATCH] Properly await execution of child processes in run_command. This is, for example, used in the onclick of buttons. Not waiting caused child processes not to be cleaned up correctly. Thus, this fixes #75. --- src/widgets/mod.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/widgets/mod.rs b/src/widgets/mod.rs index 2f984a0..52d893d 100644 --- a/src/widgets/mod.rs +++ b/src/widgets/mod.rs @@ -1,6 +1,7 @@ use crate::{ config::{element, window_definition::WindowName}, eww_state::*, + print_result_err, value::{AttrName, AttrValue, VarName}, }; use anyhow::*; @@ -18,9 +19,12 @@ const CMD_STRING_PLACEHODLER: &str = "{}"; /// placeholder ('{}') which will be replaced by the value provided as [`arg`] pub(self) fn run_command(cmd: &str, arg: T) { let cmd = cmd.replace(CMD_STRING_PLACEHODLER, &format!("{}", arg)); - if let Err(e) = Command::new("/bin/sh").arg("-c").arg(cmd).spawn() { - eprintln!("{}", e); - } + let command_result = Command::new("/bin/sh") + .arg("-c") + .arg(&cmd) + .spawn() + .and_then(|mut child| child.wait()); + print_result_err!(format!("executing command {}", &cmd), command_result); } struct BuilderArgs<'a, 'b, 'c, 'd, 'e> {