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.
This commit is contained in:
parent
080696a751
commit
4404ab4d5d
1 changed files with 7 additions and 3 deletions
|
@ -1,6 +1,7 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
config::{element, window_definition::WindowName},
|
config::{element, window_definition::WindowName},
|
||||||
eww_state::*,
|
eww_state::*,
|
||||||
|
print_result_err,
|
||||||
value::{AttrName, AttrValue, VarName},
|
value::{AttrName, AttrValue, VarName},
|
||||||
};
|
};
|
||||||
use anyhow::*;
|
use anyhow::*;
|
||||||
|
@ -18,9 +19,12 @@ const CMD_STRING_PLACEHODLER: &str = "{}";
|
||||||
/// placeholder ('{}') which will be replaced by the value provided as [`arg`]
|
/// placeholder ('{}') which will be replaced by the value provided as [`arg`]
|
||||||
pub(self) fn run_command<T: std::fmt::Display>(cmd: &str, arg: T) {
|
pub(self) fn run_command<T: std::fmt::Display>(cmd: &str, arg: T) {
|
||||||
let cmd = cmd.replace(CMD_STRING_PLACEHODLER, &format!("{}", arg));
|
let cmd = cmd.replace(CMD_STRING_PLACEHODLER, &format!("{}", arg));
|
||||||
if let Err(e) = Command::new("/bin/sh").arg("-c").arg(cmd).spawn() {
|
let command_result = Command::new("/bin/sh")
|
||||||
eprintln!("{}", e);
|
.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> {
|
struct BuilderArgs<'a, 'b, 'c, 'd, 'e> {
|
||||||
|
|
Loading…
Add table
Reference in a new issue