From 2c66abcf2050bb5cb65e4d7f06c3a1b01806adf2 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Sun, 21 Jan 2024 18:27:12 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9C=8B=E8=B5=B7=E6=9D=A5=E5=A5=BD=E5=A4=9A?= =?UTF-8?q?=E4=BA=86=EF=BC=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config.rs | 1 + src/win.rs | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/config.rs b/src/config.rs index 327aea0..b101277 100644 --- a/src/config.rs +++ b/src/config.rs @@ -46,6 +46,7 @@ impl Config { let args: Vec = std::env::args().collect(); // 先检查有没有 --help if args.contains(&"--help".to_string()) { + println!("v {}", crate::VERSION); println!("{}", HELP_MESSAGE); return None; } diff --git a/src/win.rs b/src/win.rs index 17619e4..9069527 100644 --- a/src/win.rs +++ b/src/win.rs @@ -1,6 +1,12 @@ use crate::config::Config; use winapi::um::wincon; +fn free_console() { + unsafe { + wincon::FreeConsole(); + } +} + pub fn call_bin(config: &Config) { // 先切换工作目录 if let Some(chdir) = config.chdir.as_ref() { @@ -11,6 +17,7 @@ pub fn call_bin(config: &Config) { .args(&config.bin_arg) .spawn() .expect("执行失败"); + free_console(); } pub fn run(config: &Config) { @@ -19,9 +26,7 @@ pub fn run(config: &Config) { std::thread::sleep(std::time::Duration::from_secs(2)); println!("睡醒了"); // 尝试 FreeConsole 看看 - unsafe { - wincon::FreeConsole(); - } + // free_console(); println!("FreeConsole 了"); // 调用可执行文件 call_bin(&config);