Compare commits
No commits in common. "3fe1e049fb877399380df00bbd8db9f42f687ff1" and "4536d45a9e18def8d88a41b95b4fa17bc5e574d6" have entirely different histories.
3fe1e049fb
...
4536d45a9e
|
@ -205,19 +205,6 @@ bool stdio_client::start_server_process() {
|
||||||
|
|
||||||
LOG_INFO("Starting server process: ", command_);
|
LOG_INFO("Starting server process: ", command_);
|
||||||
|
|
||||||
auto convert_to_string = [](const json& value) -> std::string {
|
|
||||||
if (value.is_string()) {
|
|
||||||
return value.get<std::string>();
|
|
||||||
} else if (value.is_number_integer()) {
|
|
||||||
return std::to_string(value.get<int>());
|
|
||||||
} else if (value.is_number_float()) {
|
|
||||||
return std::to_string(value.get<double>());
|
|
||||||
} else if (value.is_boolean()) {
|
|
||||||
return value.get<bool>() ? "true" : "false";
|
|
||||||
}
|
|
||||||
throw std::runtime_error("Unsupported type");
|
|
||||||
};
|
|
||||||
|
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
// Windows implementation
|
// Windows implementation
|
||||||
SECURITY_ATTRIBUTES sa;
|
SECURITY_ATTRIBUTES sa;
|
||||||
|
@ -275,11 +262,26 @@ bool stdio_client::start_server_process() {
|
||||||
// Prepare environment variables
|
// Prepare environment variables
|
||||||
std::string env_block;
|
std::string env_block;
|
||||||
if (!env_vars_.empty()) {
|
if (!env_vars_.empty()) {
|
||||||
for (const auto& [key, value] : env_vars_.items()) {
|
char* system_env = GetEnvironmentStringsA();
|
||||||
std::string env_var = key + "=" + convert_to_string(value);
|
if (system_env) {
|
||||||
env_block += env_var + '\0';
|
// Copy system environment variables
|
||||||
|
const char* env_ptr = system_env;
|
||||||
|
while (*env_ptr) {
|
||||||
|
std::string env_var(env_ptr);
|
||||||
|
env_block += env_var + '\0';
|
||||||
|
env_ptr += env_var.size() + 1;
|
||||||
|
}
|
||||||
|
FreeEnvironmentStringsA(system_env);
|
||||||
|
|
||||||
|
// Add custom environment variables
|
||||||
|
for (auto it = env_vars_.begin(); it != env_vars_.end(); ++it) {
|
||||||
|
std::string env_var = it.key() + "=" + it.value().get<std::string>();
|
||||||
|
env_block += env_var + '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add terminator
|
||||||
|
env_block += '\0';
|
||||||
}
|
}
|
||||||
env_block += '\0';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create child process
|
// Create child process
|
||||||
|
@ -357,10 +359,10 @@ bool stdio_client::start_server_process() {
|
||||||
|
|
||||||
// Set environment variables
|
// Set environment variables
|
||||||
if (!env_vars_.empty()) {
|
if (!env_vars_.empty()) {
|
||||||
for (const auto& [key, value] : env_vars_.items()) {
|
for (auto it = env_vars_.begin(); it != env_vars_.end(); ++it) {
|
||||||
std::string env_var = key + "=" + convert_to_string(value);
|
std::string env_var = it.key() + "=" + it.value().get<std::string>();
|
||||||
if (putenv(const_cast<char*>(env_var.c_str())) != 0) {
|
if (putenv(const_cast<char*>(env_var.c_str())) != 0) {
|
||||||
LOG_ERROR("Failed to set environment variable: ", key);
|
LOG_ERROR("Failed to set environment variable: ", it.key());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue