Unverified Commit 1b889141 authored by stuartmorgan's avatar stuartmorgan Committed by GitHub

Redirect stdout/stderr in Windows template (#56089)

Redirects stdout/stderr in the Windows template when creating a console. This fixes the console opened when running from Visual Studio to actually show output, instead of being empty.

Fixes #53169
parent 3818003d
......@@ -27,6 +27,9 @@
<ClCompile Include="runner\flutter_window.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="runner\utils.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="runner\win32_window.cpp">
<Filter>Source Files</Filter>
</ClCompile>
......@@ -53,6 +56,9 @@
<ClInclude Include="runner\flutter_window.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="runner\utils.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="runner\win32_window.h">
<Filter>Header Files</Filter>
</ClInclude>
......
......@@ -227,6 +227,7 @@
<ClCompile Include="runner\main.cpp" />
<ClCompile Include="flutter\generated_plugin_registrant.cc" />
<ClCompile Include="runner\run_loop.cpp" />
<ClCompile Include="runner\utils.cpp" />
<ClCompile Include="runner\window_configuration.cpp" />
<ClCompile Include="runner\win32_window.cpp" />
<ClCompile Include="runner\flutter_window.cpp" />
......@@ -238,6 +239,7 @@
<ClInclude Include="flutter\generated_plugin_registrant.h" />
<ClInclude Include="runner\resource.h" />
<ClInclude Include="runner\run_loop.h" />
<ClInclude Include="runner\utils.h" />
<ClInclude Include="runner\win32_window.h" />
<ClInclude Include="runner\flutter_window.h" />
<ClInclude Include="runner\window_configuration.h" />
......
......@@ -4,19 +4,19 @@
#include "flutter_window.h"
#include "run_loop.h"
#include "utils.h"
#include "window_configuration.h"
int APIENTRY wWinMain(_In_ HINSTANCE instance,
_In_opt_ HINSTANCE prev,
_In_ wchar_t* command_line,
_In_ int show_command) {
int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
_In_ wchar_t *command_line, _In_ int show_command) {
// Attach to console when present (e.g., 'flutter run') or create a
// new console when running with a debugger.
if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) {
::AllocConsole();
CreateAndAttachConsole();
}
// Initialize COM, so that it is available for use in the library and/or plugins.
// Initialize COM, so that it is available for use in the library and/or
// plugins.
::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
RunLoop run_loop;
......
#include "utils.h"
#include <flutter_windows.h>
#include <io.h>
#include <stdio.h>
#include <windows.h>
#include <iostream>
void CreateAndAttachConsole() {
if (::AllocConsole()) {
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();
FlutterDesktopResyncOutputStreams();
}
}
#ifndef CONSOLE_UTILS_H_
#define CONSOLE_UTILS_H_
// Creates a console for the process, and redirects stdout and stderr to
// it for both the runner and the Flutter library.
void CreateAndAttachConsole();
#endif // CONSOLE_UTILS_H_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment