Skip to content

Commit

Permalink
Supress stdout and stderr for non-windows platforms
Browse files Browse the repository at this point in the history
Fixes #19
  • Loading branch information
Sebastian Thiel committed Jul 3, 2019
1 parent c290817 commit 4e3574a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
22 changes: 16 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
extern crate winapi;

#[cfg(not(target_os = "windows"))]
use std::process::Command;
use std::process::{Command, Stdio};

use std::ffi::OsStr;
use std::io;
Expand All @@ -52,7 +52,12 @@ pub fn that<T: AsRef<OsStr> + Sized>(path: T) -> io::Result<ExitStatus> {
let path_ref = path.as_ref();
let mut last_err: io::Error = io::Error::from_raw_os_error(0);
for program in &["xdg-open", "gnome-open", "kde-open"] {
match Command::new(program).arg(path_ref).spawn() {
match Command::new(program)
.stdout(Stdio::null())
.stderr(Stdio::null())
.arg(path_ref)
.spawn()
{
Ok(mut child) => return child.wait(),
Err(err) => {
last_err = err;
Expand All @@ -65,11 +70,11 @@ pub fn that<T: AsRef<OsStr> + Sized>(path: T) -> io::Result<ExitStatus> {

#[cfg(target_os = "windows")]
pub fn that<T: AsRef<OsStr> + Sized>(path: T) -> io::Result<ExitStatus> {
use winapi::ctypes::c_int;
use winapi::um::shellapi::ShellExecuteW;
use std::os::windows::ffi::OsStrExt;
use std::os::windows::process::ExitStatusExt;
use std::ptr;
use winapi::ctypes::c_int;
use winapi::um::shellapi::ShellExecuteW;

const SW_SHOW: c_int = 5;

Expand All @@ -94,13 +99,18 @@ pub fn that<T: AsRef<OsStr> + Sized>(path: T) -> io::Result<ExitStatus> {

#[cfg(target_os = "macos")]
pub fn that<T: AsRef<OsStr> + Sized>(path: T) -> io::Result<ExitStatus> {
Command::new("open").arg(path.as_ref()).spawn()?.wait()
Command::new("open")
.stdout(Stdio::null())
.stderr(Stdio::null())
.arg(path.as_ref())
.spawn()?
.wait()
}

#[cfg(windows)]
mod windows {
use std::io;
use std::ffi::OsStr;
use std::io;
use std::os::windows::ffi::OsStrExt;

pub fn convert_path(path: &OsStr) -> io::Result<Vec<u16>> {
Expand Down
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ fn main() {
"An error occourred when opening '{}': {}",
path_or_url,
err
).ok();
)
.ok();
process::exit(3);
}
}

0 comments on commit 4e3574a

Please sign in to comment.