Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No console output for Windows when run from Visual Studio #53169

Closed
stuartmorgan opened this issue Mar 24, 2020 · 3 comments · Fixed by #56089
Closed

No console output for Windows when run from Visual Studio #53169

stuartmorgan opened this issue Mar 24, 2020 · 3 comments · Fixed by #56089
Assignees
Labels
a: desktop Running on desktop platform-windows Building on or for Windows specifically

Comments

@stuartmorgan
Copy link
Contributor

When running under the VS debugger, I'm getting a console window, but nothing shows up in it:

  • No observatory log line, so I can't get the observatory URL to attach to
  • No Flutter exceptions

In theory there's code in the runner that is supposed to handle this (which is why the console window opens in the first place), but it's not working for me (and I'm not sure if it ever actually worked).

@stuartmorgan
Copy link
Contributor Author

I dug into this a bit. When we create a console we need to freopen stdout/stderr not only in the runner, but in the engine--I believe because we are using static CRT linking.

Adding it in the runner is easy since we already know when we are creating the console. The engine side will need a bit more logic since we need to know when we should be doing it; I believe the Chromium output redirection code will be useful model in getting that right.

@deekay42
Copy link

As a temporary workaround to show all output, replace this line in main.cpp

int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
   _In_ wchar_t* command_line, _In_ int show_command) {

with
int main() {
and remove

if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) {
       ::AllocConsole();

@stuartmorgan stuartmorgan self-assigned this Apr 30, 2020
stuartmorgan added a commit to stuartmorgan/engine that referenced this issue Apr 30, 2020
When creating a console on Windows, stdout/stderr aren't wired up to it.
They need to be re-opened afeter the console is created, and that needs
to be done separately in the engine due to the use of static runtime
linking. This provides a helper method that the runner can call when
creating a console so that output will work as expected.

Part of flutter/flutter#53169
stuartmorgan added a commit to flutter/engine that referenced this issue May 1, 2020
When creating a console on Windows, stdout/stderr aren't wired up to it.
They need to be re-opened afeter the console is created, and that needs
to be done separately in the engine due to the use of static runtime
linking. This provides a helper method that the runner can call when
creating a console so that output will work as expected.

Part of flutter/flutter#53169
stuartmorgan added a commit that referenced this issue May 3, 2020
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
@lock
Copy link

lock bot commented May 21, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@lock lock bot locked and limited conversation to collaborators May 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a: desktop Running on desktop platform-windows Building on or for Windows specifically
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants