diff --git a/src/lib.rs b/src/lib.rs index f45c5a5..200a1b1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,7 +25,7 @@ mod prelude { pub use std::io::prelude::*; pub use libc::{EXIT_FAILURE, EXIT_SUCCESS}; pub use regex::Regex; - pub use std::path::Path; + pub use std::path::{Path, PathBuf}; pub use std::{cmp, env, fs, fmt, io, iter, process}; } diff --git a/src/platform.rs b/src/platform.rs index 007ce12..11f7f0e 100644 --- a/src/platform.rs +++ b/src/platform.rs @@ -44,7 +44,22 @@ impl PlatformInterface for Platform { #[cfg(windows)] impl PlatformInterface for Platform { fn make_shebang_command(path: &Path, command: &str, argument: Option<&str>) -> process::Command { - let mut cmd = process::Command::new(command); + let mut cmd = match env::var_os("EXEPATH") { + Some(exepath) => { + // On MinGW, `EXEPATH` is the root of the installation. Use it to + // construct a full windows path to the binary in the shebang line. + let mut translated_command = PathBuf::from(exepath); + for part in command.split("/") { + translated_command.push(part); + } + process::Command::new(translated_command) + } + None => { + // We're not on MinGW >_< The path in the shebang might be a windows + // path, in which case it'll work, so just use it and hope for the best. + process::Command::new(command) + } + }; if let Some(argument) = argument { cmd.arg(argument); }