mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2025-07-01 15:36:10 +00:00
fix game's stdout/stderr printing to launcher console on linux
This commit is contained in:
parent
96d579f64b
commit
b76930b0bd
@ -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");
|
||||
|
Loading…
x
Reference in New Issue
Block a user