use std::io;
use std::process::{Command, Output, Stdio};
#[cfg(target_os = "windows")]
const SHELL: &str = "cmd";
#[cfg(target_os = "windows")]
const SHELL_FLAG: &str = "/C";
#[cfg(not(target_os = "windows"))]
const SHELL: &str = "bash";
#[cfg(not(target_os = "windows"))]
const SHELL_FLAG: &str = "-c";
pub fn run(cmd: &str) -> io::Result<()> {
let mut child = Command::new(SHELL)
.arg(SHELL_FLAG)
.arg(cmd)
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.spawn()?;
let status = child.wait()?;
if !status.success() {
eprintln!("Command exited with: {}", status);
}
Ok(())
}
pub fn run_and_get_stdout(cmd: &str) -> io::Result<String> {
let output = call(cmd)?;
Ok(String::from_utf8_lossy(&output.stdout).to_string())
}
pub fn call(command: &str) -> io::Result<Output> {
Command::new(SHELL)
.arg(SHELL_FLAG)
.arg(command)
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.output()
}