diff --git a/engine/src/flutter/shell/platform/windows/flutter_windows.cc b/engine/src/flutter/shell/platform/windows/flutter_windows.cc index c53b055fffe..805ca6cd31a 100644 --- a/engine/src/flutter/shell/platform/windows/flutter_windows.cc +++ b/engine/src/flutter/shell/platform/windows/flutter_windows.cc @@ -5,6 +5,7 @@ #include "flutter/shell/platform/windows/public/flutter_windows.h" #include +#include #include #include @@ -224,6 +225,17 @@ UINT FlutterDesktopGetDpiForMonitor(HMONITOR monitor) { return flutter::GetDpiForMonitor(monitor); } +void FlutterDesktopResyncOutputStreams() { + FILE* unused; + if (freopen_s(&unused, "CONOUT$", "w", stdout)) { + _dup2(_fileno(stdout), 1); + } + if (freopen_s(&unused, "CONOUT$", "w", stderr)) { + _dup2(_fileno(stdout), 2); + } + std::ios::sync_with_stdio(); +} + FlutterDesktopEngineRef FlutterDesktopRunEngine( const FlutterDesktopEngineProperties& engine_properties) { auto engine = RunFlutterEngine(nullptr, engine_properties); diff --git a/engine/src/flutter/shell/platform/windows/public/flutter_windows.h b/engine/src/flutter/shell/platform/windows/public/flutter_windows.h index 7d9c4155ad3..633169a4cf4 100644 --- a/engine/src/flutter/shell/platform/windows/public/flutter_windows.h +++ b/engine/src/flutter/shell/platform/windows/public/flutter_windows.h @@ -110,6 +110,11 @@ FLUTTER_EXPORT UINT FlutterDesktopGetDpiForHWND(HWND hwnd); // DPI of 96 is returned. FLUTTER_EXPORT UINT FlutterDesktopGetDpiForMonitor(HMONITOR monitor); +// Reopens stdout and stderr and resysncs the standard library output streams. +// Should be called if output is being directed somewhere in the runner process +// (e.g., after an AllocConsole call). +FLUTTER_EXPORT void FlutterDesktopResyncOutputStreams(); + // Runs an instance of a headless Flutter engine. // // Returns a null pointer in the event of an error.