diff --git a/src/windows.rs b/src/windows.rs index 7bd5bcb..b2b8658 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -1,36 +1,9 @@ -use std::{ - ffi::{OsStr, OsString}, - io, - os::windows::ffi::OsStrExt, - ptr, -}; +use std::{ffi::OsStr, io}; -use std::os::raw::c_int; - -use crate::IntoResult; - -fn convert_path(path: &OsStr) -> io::Result> { - let mut quoted_path = OsString::with_capacity(path.len()); - - // Surround path with double quotes "" to handle spaces in path. - quoted_path.push("\""); - quoted_path.push(&path); - quoted_path.push("\""); - - let mut wide_chars: Vec<_> = quoted_path.encode_wide().collect(); - if wide_chars.iter().any(|&u| u == 0) { - return Err(io::Error::new( - io::ErrorKind::InvalidInput, - "path contains NUL byte(s)", - )); - } - wide_chars.push(0); - Ok(wide_chars) -} +use crate::{CommandExt, IntoResult}; pub fn that>(path: T) -> io::Result<()> { - let path = convert_path(path.as_ref())?; - Command::new("cmd") + std::process::Command::new("cmd") .arg("/c") .arg("start") .arg(path.as_ref()) @@ -39,8 +12,7 @@ pub fn that>(path: T) -> io::Result<()> { } pub fn with>(path: T, app: impl Into) -> io::Result<()> { - let path = convert_path(path.as_ref())?; - Command::new("cmd") + std::process::Command::new("cmd") .arg("/c") .arg(app.into()) .arg(path.as_ref())