diff --git a/modules/juce_events/messages/juce_ApplicationBase.cpp b/modules/juce_events/messages/juce_ApplicationBase.cpp index f130bf4199..72657e02f5 100644 --- a/modules/juce_events/messages/juce_ApplicationBase.cpp +++ b/modules/juce_events/messages/juce_ApplicationBase.cpp @@ -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