Execute the server from the same directory the main executable is

This commit is contained in:
Vladimir Borisov 2024-04-22 12:53:53 +03:00
parent f76435e745
commit b8c68029ed

View file

@ -1,8 +1,7 @@
use native_windows_gui as nwg; use native_windows_gui as nwg;
use std::os::windows::process::CommandExt; use std::{
use std::process::Command; env, fs, os::windows::process::CommandExt, path, process::Command, thread, time::Duration,
use std::thread; };
use std::time::Duration;
use winapi::um::{ use winapi::um::{
processthreadsapi::GetCurrentProcess, processthreadsapi::GetCurrentProcess,
winbase::CreateJobObjectA, winbase::CreateJobObjectA,
@ -44,9 +43,15 @@ impl StremioServer {
GetCurrentProcess(), GetCurrentProcess(),
); );
} }
let mut path = env::current_exe()
.and_then(fs::canonicalize)
.expect("Cannot get the current executable path");
path.pop();
loop { loop {
let child = Command::new("./stremio-runtime") let runtime_path = path.clone().join(path::Path::new("stremio-runtime"));
.arg("server.js") let server_path = path.clone().join(path::Path::new("server.js"));
let child = Command::new(runtime_path)
.arg(server_path)
.creation_flags(CREATE_NO_WINDOW) .creation_flags(CREATE_NO_WINDOW)
.spawn(); .spawn();
match child { match child {