covey_plugin/
spawn.rs

1//! Utilities for spawning processes.
2//!
3//! These are intended for use in command callbacks. They will spawn processes without catching
4//! any stdio.
5
6use std::{
7    ffi::OsStr,
8    process::{Command, Stdio},
9};
10
11pub fn program(
12    program: impl AsRef<OsStr>,
13    args: impl IntoIterator<Item: AsRef<OsStr>>,
14) -> std::io::Result<()> {
15    Command::new(program)
16        .args(args)
17        .stdin(Stdio::null())
18        .stdout(Stdio::null())
19        .stderr(Stdio::null())
20        .spawn()?;
21
22    Ok(())
23}
24
25/// Runs a string as a shell script.
26pub fn script(script: impl AsRef<OsStr>) -> std::io::Result<()> {
27    self::program("sh", ["-c".as_ref(), script.as_ref()])
28}