From bdac55ef0367756bf8670b28f1342302d5992a66 Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Thu, 17 Oct 2024 18:33:07 +0700 Subject: [PATCH] fix: pass params when spawn process --- engine/commands/server_start_cmd.cc | 38 ++++++++++++++++++++++------- engine/utils/logging_utils.h | 2 +- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/engine/commands/server_start_cmd.cc b/engine/commands/server_start_cmd.cc index 48ff59e29..6b30c411b 100644 --- a/engine/commands/server_start_cmd.cc +++ b/engine/commands/server_start_cmd.cc @@ -30,6 +30,20 @@ bool TryConnectToServer(const std::string& host, int port) { ServerStartCmd::ServerStartCmd() {} bool ServerStartCmd::Exec(const std::string& host, int port) { + auto get_config_file_path = []() -> std::string { + if (file_manager_utils::cortex_config_file_path.empty()) { + return file_manager_utils::GetConfigurationPath().string(); + } + return file_manager_utils::cortex_config_file_path; + }; + + auto get_data_folder_path = []() -> std::string { + if (file_manager_utils::cortex_data_folder_path.empty()) { + return file_manager_utils::GetCortexDataPath().string(); + } + return file_manager_utils::cortex_data_folder_path; + }; + #if defined(_WIN32) || defined(_WIN64) // Windows-specific code to create a new process STARTUPINFO si; @@ -39,8 +53,10 @@ bool ServerStartCmd::Exec(const std::string& host, int port) { si.cb = sizeof(si); ZeroMemory(&pi, sizeof(pi)); auto exe = commands::GetCortexBinary(); - std::string cmds = - cortex_utils::GetCurrentPath() + "/" + exe + " --start-server"; + std::string params = "--start-server"; + params += " --config_file_path " + get_config_file_path(); + params += " --data_folder_path " + get_data_folder_path(); + std::string cmds = cortex_utils::GetCurrentPath() + "/" + exe + " " + params; // Create child process if (!CreateProcess( NULL, // No module name (use command line) @@ -58,11 +74,12 @@ bool ServerStartCmd::Exec(const std::string& host, int port) { std::cout << "Could not start server: " << GetLastError() << std::endl; return false; } else { - if(!TryConnectToServer(host, port)) { - return false; + if (!TryConnectToServer(host, port)) { + return false; } std::cout << "Server started" << std::endl; - std::cout << "API Documentation available at: http://" << host << ":" << port << std::endl; + std::cout << "API Documentation available at: http://" << host << ":" + << port << std::endl; } #else @@ -92,14 +109,17 @@ bool ServerStartCmd::Exec(const std::string& host, int port) { #endif auto exe = commands::GetCortexBinary(); std::string p = cortex_utils::GetCurrentPath() + "/" + exe; - execl(p.c_str(), exe.c_str(), "--start-server", (char*)0); + execl(p.c_str(), exe.c_str(), "--start-server", "--config_file_path", + get_config_file_path().c_str(), "--data_folder_path", + get_data_folder_path().c_str(), (char*)0); } else { // Parent process - if(!TryConnectToServer(host, port)) { - return false; + if (!TryConnectToServer(host, port)) { + return false; } std::cout << "Server started" << std::endl; - std::cout << "API Documentation available at: http://" << host << ":" << port << std::endl; + std::cout << "API Documentation available at: http://" << host << ":" + << port << std::endl; } #endif return true; diff --git a/engine/utils/logging_utils.h b/engine/utils/logging_utils.h index f4376cb01..8891167ce 100644 --- a/engine/utils/logging_utils.h +++ b/engine/utils/logging_utils.h @@ -36,4 +36,4 @@ inline bool log_verbose = false; } else { \ LOG_ERROR << msg; \ std::cout << msg << std::endl; \ - } \ No newline at end of file + }