rust后台运行可执行文件
#![cfg_attr(
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
)]
use std::{
cell::RefCell,
os::windows::process::CommandExt,
process::{Child, Command},
};
use tauri::Manager;
fn run_core() -> Child {
return Command::new("core/sdib-core")
.creation_flags(0x08000000)
.arg("-loglevel")
.arg("debug")
.spawn()
.expect("failed to execute core process");
}
fn main() {
let child = RefCell::new(run_core());
tauri::Builder::default()
.setup(|app| {
let window = app.get_window("main").unwrap();
window.on_window_event(move |event| {
if let tauri::WindowEvent::Destroyed = event {
child
.borrow_mut()
.kill()
.expect("core process wasn't running");
child.borrow_mut().wait().unwrap();
}
});
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
本文来自博客园,作者:非空丶,转载请注明原文链接:https://www.cnblogs.com/wsshow/articles/18741892

浙公网安备 33010602011771号