Browse Source

Only reopen stdout, stderr, stdin if they haven't already been opened by a redirect

And fix a warning along the way
tags/2021-05-28
hogliux 9 years ago
parent
commit
d4933111db
1 changed files with 7 additions and 3 deletions
  1. +7
    -3
      modules/juce_events/messages/juce_ApplicationBase.cpp

+ 7
- 3
modules/juce_events/messages/juce_ApplicationBase.cpp View File

@@ -261,9 +261,13 @@ bool JUCEApplicationBase::initialiseApp()
if (AttachConsole (ATTACH_PARENT_PROCESS) != 0)
{
// if we've launched a GUI app from cmd.exe or PowerShell, we need this to enable printf etc.
freopen("CON", "w", stdout);
freopen("CON", "w", stderr);
freopen("CON", "r", stdin);
// However, only reassign stdout, stderr, stdin if they have not been already opened by
// a redirect or similar.
FILE* ignore;
if (_fileno(stdout) < 0) freopen_s (&ignore, "CONOUT$", "w", stdout);
if (_fileno(stderr) < 0) freopen_s (&ignore, "CONOUT$", "w", stderr);
if (_fileno(stdin) < 0) freopen_s (&ignore, "CONIN$", "r", stdin);
}
#endif


Loading…
Cancel
Save