From 8f199b9fa1c1f1ae6d1bb50198ea0d39a5d958a7 Mon Sep 17 00:00:00 2001 From: Biswaroop Bhattacharjee <biswaroop08@gmail.com> Date: Thu, 26 Oct 2023 05:49:46 +0530 Subject: [PATCH] fix: log_file use at start service (#420) --- src-tauri/src/controller_binaries.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src-tauri/src/controller_binaries.rs b/src-tauri/src/controller_binaries.rs index 40cde5d3..cd3a620e 100644 --- a/src-tauri/src/controller_binaries.rs +++ b/src-tauri/src/controller_binaries.rs @@ -6,7 +6,6 @@ use crate::errors::{Context, Result}; use crate::{Service, SharedState}; use std::collections::HashMap; use std::path::PathBuf; -use std::process::Stdio; use sys_info::mem_info; use futures::future; @@ -61,7 +60,7 @@ pub async fn start_service( let log_path = PathBuf::from(&service_dir).join(format!("{}.log", service_id)); // Use synchronous std::fs::File for log file creation - let _log_file = std::fs::OpenOptions::new() + let log_file = std::fs::OpenOptions::new() .create(true) .append(true) .open(&log_path) @@ -117,8 +116,12 @@ pub async fn start_service( let child = Command::new(&binary_path) .current_dir(service_dir) .args(args) - .stdout(Stdio::inherit()) - .stderr(Stdio::inherit()) + .stdout(std::process::Stdio::from( + log_file + .try_clone() + .with_context(|| "Failed to clone log file handle")?, + )) + .stderr(std::process::Stdio::from(log_file)) .spawn() .map_err(|e| format!("Failed to spawn child process: {}", e))?; let mut running_services_guard = state.running_services.lock().await;