Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 00a26cc

Browse files
fix: pass params when spawn process (#1516)
Co-authored-by: vansangpfiev <sang@jan.ai>
1 parent 1e1c5e0 commit 00a26cc

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

engine/commands/server_start_cmd.cc

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ bool TryConnectToServer(const std::string& host, int port) {
3030
ServerStartCmd::ServerStartCmd() {}
3131

3232
bool ServerStartCmd::Exec(const std::string& host, int port) {
33+
auto get_config_file_path = []() -> std::string {
34+
if (file_manager_utils::cortex_config_file_path.empty()) {
35+
return file_manager_utils::GetConfigurationPath().string();
36+
}
37+
return file_manager_utils::cortex_config_file_path;
38+
};
39+
40+
auto get_data_folder_path = []() -> std::string {
41+
if (file_manager_utils::cortex_data_folder_path.empty()) {
42+
return file_manager_utils::GetCortexDataPath().string();
43+
}
44+
return file_manager_utils::cortex_data_folder_path;
45+
};
46+
3347
#if defined(_WIN32) || defined(_WIN64)
3448
// Windows-specific code to create a new process
3549
STARTUPINFO si;
@@ -39,8 +53,10 @@ bool ServerStartCmd::Exec(const std::string& host, int port) {
3953
si.cb = sizeof(si);
4054
ZeroMemory(&pi, sizeof(pi));
4155
auto exe = commands::GetCortexBinary();
42-
std::string cmds =
43-
cortex_utils::GetCurrentPath() + "/" + exe + " --start-server";
56+
std::string params = "--start-server";
57+
params += " --config_file_path " + get_config_file_path();
58+
params += " --data_folder_path " + get_data_folder_path();
59+
std::string cmds = cortex_utils::GetCurrentPath() + "/" + exe + " " + params;
4460
// Create child process
4561
if (!CreateProcess(
4662
NULL, // No module name (use command line)
@@ -58,11 +74,12 @@ bool ServerStartCmd::Exec(const std::string& host, int port) {
5874
std::cout << "Could not start server: " << GetLastError() << std::endl;
5975
return false;
6076
} else {
61-
if(!TryConnectToServer(host, port)) {
62-
return false;
77+
if (!TryConnectToServer(host, port)) {
78+
return false;
6379
}
6480
std::cout << "Server started" << std::endl;
65-
std::cout << "API Documentation available at: http://" << host << ":" << port << std::endl;
81+
std::cout << "API Documentation available at: http://" << host << ":"
82+
<< port << std::endl;
6683
}
6784

6885
#else
@@ -92,14 +109,17 @@ bool ServerStartCmd::Exec(const std::string& host, int port) {
92109
#endif
93110
auto exe = commands::GetCortexBinary();
94111
std::string p = cortex_utils::GetCurrentPath() + "/" + exe;
95-
execl(p.c_str(), exe.c_str(), "--start-server", (char*)0);
112+
execl(p.c_str(), exe.c_str(), "--start-server", "--config_file_path",
113+
get_config_file_path().c_str(), "--data_folder_path",
114+
get_data_folder_path().c_str(), (char*)0);
96115
} else {
97116
// Parent process
98-
if(!TryConnectToServer(host, port)) {
99-
return false;
117+
if (!TryConnectToServer(host, port)) {
118+
return false;
100119
}
101120
std::cout << "Server started" << std::endl;
102-
std::cout << "API Documentation available at: http://" << host << ":" << port << std::endl;
121+
std::cout << "API Documentation available at: http://" << host << ":"
122+
<< port << std::endl;
103123
}
104124
#endif
105125
return true;

engine/utils/logging_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ inline bool log_verbose = false;
3636
} else { \
3737
LOG_ERROR << msg; \
3838
std::cout << msg << std::endl; \
39-
}
39+
}

0 commit comments

Comments
 (0)