1use crate::errors::*;
2use std::ffi::OsStr;
3use std::io;
4use std::process::Command;
5
6#[cfg(target_os = "macos")]
7mod raw_darwin;
8#[cfg(target_os = "macos")]
9pub use raw_darwin::*;
10
11#[cfg(target_os = "linux")]
12mod raw_linux;
13#[cfg(target_os = "linux")]
14pub use raw_linux::*;
15
16pub fn run_shell<S: AsRef<OsStr>>(cmd_ref: S) -> Result<()> {
17 let cmd: String = cmd_ref.as_ref().to_str().unwrap().into();
18 let result: std::process::Output = Command::new("env")
20 .arg("bash")
21 .arg("-c")
22 .arg(cmd_ref)
23 .output()
24 .context(RunShellError { cmd: cmd.to_owned() })?;
25 if !result.status.success() {
26 let stderr: String = String::from_utf8_lossy(result.stderr.as_ref()).into();
27 return ShellResultError {
28 result: stderr,
29 cmd: cmd,
30 }.fail();
31 }
32 let stdout = String::from_utf8_lossy(result.stdout.as_ref());
33 print!("{}", stdout);
34 Ok(())
35}