From 5c8093ca72df2db33bd11056e4eb64da2a9c5c75 Mon Sep 17 00:00:00 2001 From: Pylogmon Date: Fri, 21 Jun 2024 14:50:59 +0800 Subject: [PATCH] fix: invoke error --- src-tauri/src/cmd.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src-tauri/src/cmd.rs b/src-tauri/src/cmd.rs index 04456bb229..f6a00f0cf0 100644 --- a/src-tauri/src/cmd.rs +++ b/src-tauri/src/cmd.rs @@ -182,6 +182,8 @@ pub fn run_binary( cmd_name: String, args: Vec, ) -> Result { + #[cfg(target_os = "windows")] + use std::os::windows::process::CommandExt; use std::process::Command; let config_path = dirs::config_dir().unwrap(); @@ -190,10 +192,16 @@ pub fn run_binary( let config_path = config_path.join(plugin_type); let plugin_path = config_path.join(plugin_name); - let output = Command::new(cmd_name) - .args(args) - .current_dir(plugin_path) - .output()?; + #[cfg(target_os = "windows")] + let mut cmd = Command::new("cmd"); + #[cfg(target_os = "windows")] + let cmd = cmd.creation_flags(0x08000000); + #[cfg(target_os = "windows")] + let cmd = cmd.args(["/c", &cmd_name]); + #[cfg(not(target_os = "windows"))] + let mut cmd = Command::new(&cmd_name); + + let output = cmd.args(args).current_dir(plugin_path).output()?; Ok(json!({ "stdout": String::from_utf8_lossy(&output.stdout).to_string(), "stderr": String::from_utf8_lossy(&output.stderr).to_string(),