@@ -7545,13 +7545,24 @@ int main(int argc, char *argv[])
75457545
75467546 SCP_mspdbcs_Initialise ();
75477547
7548- // If we're being evoked from a console, attach the STDIO streams to it and reopen the streams
7549- // This is needed because Windows assumes SUBSYSTEM:WINDOWS programs won't need console IO. Additionally, SDL
7550- // seems to close or otherwise grab the streams for somthing else.
7551- if (AttachConsole (ATTACH_PARENT_PROCESS)) {
7552- freopen (" CONIN$" , " r" , stdin);
7553- freopen (" CONOUT$" , " w" , stdout);
7554- freopen (" CONOUT$" , " w" , stderr);
7548+ bool keep_stdout = false ;
7549+ char envbuf[2 ];
7550+ // GetEnvironmentVariable returns the amount of stored characters on success, we're looking for the value "1"
7551+ // so we only care about the case where it successfully read exactly one character (not including the null byte).
7552+ if (GetEnvironmentVariable (" FSO_KEEP_STDOUT" , envbuf, 2 ) == 1 ) {
7553+ keep_stdout = envbuf[0 ] == ' 1' ;
7554+ }
7555+
7556+ // Only try redirecting stdout if FSO_KEEP_STDOUT is not set to "1".
7557+ if (!keep_stdout) {
7558+ // If we're being evoked from a console, attach the STDIO streams to it and reopen the streams
7559+ // This is needed because Windows assumes SUBSYSTEM:WINDOWS programs won't need console IO. Additionally, SDL
7560+ // seems to close or otherwise grab the streams for somthing else.
7561+ if (AttachConsole (ATTACH_PARENT_PROCESS)) {
7562+ freopen (" CONIN$" , " r" , stdin);
7563+ freopen (" CONOUT$" , " w" , stdout);
7564+ freopen (" CONOUT$" , " w" , stderr);
7565+ }
75557566 }
75567567#else
75577568#ifdef APPLE_APP
0 commit comments