fix game's stdout/stderr printing to launcher console on linux

This commit is contained in:
Lion Kortlepel 2024-06-28 15:37:46 +02:00
parent 96d579f64b
commit b76930b0bd
No known key found for this signature in database
GPG Key ID: 4322FF2B4C71259B

View File

@ -10,6 +10,8 @@
#include <windows.h>
#elif defined(__linux__)
#include "vdf_parser.hpp"
#include <cerrno>
#include <cstring>
#include <pwd.h>
#include <spawn.h>
#include <sys/types.h>
@ -90,11 +92,27 @@ void StartGame(std::string Dir) {
}
#elif defined(__linux__)
void StartGame(std::string Dir) {
int status;
std::string filename = (Dir + "/BinLinux/BeamNG.drive.x64");
char* argv[] = { filename.data(), NULL };
pid_t pid;
int result = posix_spawn(&pid, filename.c_str(), NULL, NULL, argv, environ);
posix_spawn_file_actions_t file_actions;
auto status = posix_spawn_file_actions_init(&file_actions);
// disable stdout
if (status != 0) {
error(std::string("posix_spawn_file_actions_init failed: ") + std::strerror(errno));
}
status = posix_spawn_file_actions_addclose(&file_actions, STDOUT_FILENO);
if (status != 0) {
error(std::string("posix_spawn_file_actions_addclose for STDOUT failed: ") + std::strerror(errno));
}
status = posix_spawn_file_actions_addclose(&file_actions, STDERR_FILENO);
if (status != 0) {
error(std::string("posix_spawn_file_actions_addclose for STDERR failed: ") + std::strerror(errno));
}
// launch the game
int result = posix_spawn(&pid, filename.c_str(), &file_actions, NULL, argv, environ);
if (result != 0) {
error("Failed to Launch the game! launcher closing soon");