Adapt new process API to windows.
This commit is contained in:
parent
921c39ba4e
commit
7677615bae
|
@ -384,7 +384,8 @@ fn daemon_main(config_set: ConfigSet) {
|
|||
let mut child = crate::process::spawn_process(
|
||||
&espanso_path.to_string_lossy().to_string(),
|
||||
&vec!["worker".to_owned()],
|
||||
).expect("unable to create worker process");
|
||||
)
|
||||
.expect("unable to create worker process");
|
||||
|
||||
// Create a monitor thread that will exit with the same non-zero code if
|
||||
// the worker thread exits
|
||||
|
@ -395,7 +396,10 @@ fn daemon_main(config_set: ConfigSet) {
|
|||
if let Ok(status) = result {
|
||||
if let Some(code) = status.code() {
|
||||
if code != 0 {
|
||||
error!("worker process exited with non-zero code: {}, exiting", code);
|
||||
error!(
|
||||
"worker process exited with non-zero code: {}, exiting",
|
||||
code
|
||||
);
|
||||
std::process::exit(code);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,27 +18,16 @@
|
|||
*/
|
||||
|
||||
use log::warn;
|
||||
use std::process::{Command, Stdio, Child};
|
||||
use widestring::WideCString;
|
||||
use std::io;
|
||||
use std::process::{Child, Command, Stdio};
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
pub fn spawn_process(cmd: &str, args: &Vec<String>) {
|
||||
// TODO: modify with https://doc.rust-lang.org/std/os/windows/process/trait.CommandExt.html
|
||||
let quoted_args: Vec<String> = args.iter().map(|arg| format!("\"{}\"", arg)).collect();
|
||||
let quoted_args = quoted_args.join(" ");
|
||||
let final_cmd = format!("\"{}\" {}", cmd, quoted_args);
|
||||
unsafe {
|
||||
let cmd_wstr = WideCString::from_str(&final_cmd);
|
||||
if let Ok(string) = cmd_wstr {
|
||||
let res = crate::bridge::windows::start_process(string.as_ptr());
|
||||
if res < 0 {
|
||||
warn!("unable to start process: {}", final_cmd);
|
||||
}
|
||||
} else {
|
||||
warn!("unable to convert process string into wide format")
|
||||
}
|
||||
}
|
||||
pub fn spawn_process(cmd: &str, args: &Vec<String>) -> io::Result<Child> {
|
||||
use std::os::windows::process::CommandExt;
|
||||
Command::new(cmd)
|
||||
.creation_flags(0x00000008) // Detached Process
|
||||
.args(args)
|
||||
.spawn()
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
|
|
Loading…
Reference in New Issue
Block a user