From 8d21006f0526256fab0fda58e058241e38442606 Mon Sep 17 00:00:00 2001 From: Diego Giagio Date: Mon, 15 Oct 2018 17:38:17 +0200 Subject: [PATCH] Supports execution of other file types on Windows, e.g. .bat, .cmd --- warp-runner/src/executor.rs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/warp-runner/src/executor.rs b/warp-runner/src/executor.rs index 7af2978..b5245cf 100644 --- a/warp-runner/src/executor.rs +++ b/warp-runner/src/executor.rs @@ -28,9 +28,14 @@ pub fn execute(target: &Path) -> io::Result { let args: Vec = env::args().skip(1).collect(); trace!("args={:?}", args); - Ok(Command::new(target_file_name) - .env("PATH", path_env) + do_execute(target_file_name, &args, &path_env) +} + +#[cfg(target_family = "unix")] +fn do_execute(target: &str, args: &[String], path_env: &str) -> io::Result { + Ok(Command::new(target) .args(args) + .env("PATH", path_env) .stdin(Stdio::inherit()) .stdout(Stdio::inherit()) .stderr(Stdio::inherit()) @@ -38,3 +43,21 @@ pub fn execute(target: &Path) -> io::Result { .wait()? .code().unwrap_or(1)) } + +#[cfg(target_family = "windows")] +fn do_execute(target: &str, args: &[String], path_env: &str) -> io::Result { + let mut cmd_args = Vec::with_capacity(args.len() + 2); + cmd_args.push("/c".to_string()); + cmd_args.push(target.to_string()); + cmd_args.extend_from_slice(&args); + + Ok(Command::new("cmd") + .args(cmd_args) + .env("PATH", path_env) + .stdin(Stdio::inherit()) + .stdout(Stdio::inherit()) + .stderr(Stdio::inherit()) + .spawn()? + .wait()? + .code().unwrap_or(1)) +} \ No newline at end of file