From b76930b0bdd91337974bc5f1c23c38f362911ccc Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Fri, 28 Jun 2024 15:37:46 +0200 Subject: [PATCH] fix game's stdout/stderr printing to launcher console on linux --- src/GameStart.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/GameStart.cpp b/src/GameStart.cpp index ac99d63..a3749fa 100644 --- a/src/GameStart.cpp +++ b/src/GameStart.cpp @@ -10,6 +10,8 @@ #include #elif defined(__linux__) #include "vdf_parser.hpp" +#include +#include #include #include #include @@ -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");