From 6ef3f3b1908733555b19b4a812584c1eca8c3143 Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Fri, 6 Dec 2013 00:22:02 +0100 Subject: [PATCH] Redirect to log by redefining stdout and stderr --- src/linkapp.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/linkapp.cpp b/src/linkapp.cpp index 3580486..0348dd1 100644 --- a/src/linkapp.cpp +++ b/src/linkapp.cpp @@ -590,13 +590,22 @@ void LinkApp::launch(const string &selectedFile) { string command = exec; if (!params.empty()) command += " " + params; + + if (gmenu2x->confInt["outputLogs"] #if defined(PLATFORM_A320) || defined(PLATFORM_GCW0) - if (gmenu2x->confInt["outputLogs"] && !consoleApp) - command += " &> " LOG_FILE; -#else - if (gmenu2x->confInt["outputLogs"]) - command += " &> " LOG_FILE; + && !consoleApp #endif + ) { + int fd = open(LOG_FILE, O_WRONLY | O_TRUNC | O_CREAT, 0644); + if (fd < 0) { + ERROR("Unable to open log file for write: %s\n", LOG_FILE); + } else { + fflush(stdout); + dup2(fd, STDOUT_FILENO); + dup2(fd, STDERR_FILENO); + close(fd); + } + } gmenu2x->saveSelection();