use crate::error::Error;
use std::process::Command;
#[cfg(windows)]
pub fn shell(script: &str) -> Command {
use std::os::windows::process::CommandExt;
let comspec = std::env::var_os("ComSpec").unwrap_or_else(|| "cmd.exe".into());
let mut command = Command::new(comspec);
command.arg("/C");
command.raw_arg(script);
command
}
#[cfg(not(windows))]
pub fn shell(script: &str) -> Command {
let mut command = Command::new("sh");
command.args(["-c", script]);
command
}
#[cfg(unix)]
pub fn exec(mut command: Command) -> Result<i32, Error> {
use std::os::unix::process::CommandExt;
Err(Error::Io(command.exec()))
}
#[cfg(not(unix))]
pub fn exec(mut command: Command) -> Result<i32, Error> {
Ok(command.status()?.code().unwrap_or(1))
}
pub fn wait(mut command: Command) -> Result<i32, Error> {
Ok(command.status()?.code().unwrap_or(1))
}