i3status_rs/
subprocess.rs1use std::io;
2use std::os::unix::process::CommandExt as _;
3use std::process::{Command, Stdio};
4
5pub fn spawn_process(cmd: &str, args: &[&str]) -> io::Result<()> {
7 let mut proc = Command::new(cmd);
8 proc.args(args);
9 proc.stdin(Stdio::null());
10 proc.stdout(Stdio::null());
11 unsafe {
13 proc.pre_exec(|| match libc::daemon(0, 0) {
14 -1 => Err(io::Error::other("Failed to detach new process")),
15 _ => Ok(()),
16 });
17 }
18 proc.spawn()?.wait()?;
19 Ok(())
20}
21
22pub fn spawn_shell(cmd: &str) -> io::Result<()> {
24 spawn_process("sh", &["-c", cmd])
25}
26
27pub async fn spawn_shell_sync(cmd: &str) -> io::Result<()> {
28 tokio::process::Command::new("sh")
29 .args(["-c", cmd])
30 .stdin(Stdio::null())
31 .stdout(Stdio::null())
32 .spawn()?
33 .wait()
34 .await?;
35 Ok(())
36}