Fix console output for GUI apps#88
Conversation
|
Can you clarify what you mean by "not working"? What's the reproduction case for this problem? |
|
It's not showing any output if a GUI app is run in an existing console. This can be reproduced with the default template (no framework) on Windows:
|
## Linked issue #4679 ## Summary Add anki-console.bat to Briefcase's Windows package to launch Anki in a new terminal. ## How to test - Build the installer: `./tools/ninja installer`. - Install the package at `./out/dist/`. - Confirm anki-console.bat exists in the installation folder. ## Notes Console output won't show up yet. That depends on an upstream fix: beeware/briefcase-windows-VisualStudio-template#88
This behavior is somewhat intentional. The change you've proposed here does make console output visible; but if you launch the app, the powershell/cmd prompt immediately returns, because it's a GUI app. App output ends up being mixed with the output of other commands. This is essentially a "feature" of Windows apps - a Windows GUI app immediately returns control to the command prompt; it doesn't wait until the app exits. I guess the question becomes whether it's better to always redirect app output to the log (and lean into the Windows "detached app" behavior); or accept the "mixed" output format. Is the Anki app that this comes from compiled as a console app, or a GUI app? Or is this a case where you're aware of the issue with "mixed" console output, and have come to the conclusion that it's acceptable? |
It's compiled as a GUI app, but is expected to show output to help debugging issues and is useful for advanced users since Anki has an add-on ecosystem. I'm aware of the issue of mixed console output (I remember we also had this with PyOxidizer). In the case of Anki though, we also distribute a simple anki-console.bat script and tell users to run that directly, so it's usually not an issue for us because there are no other commands using the console. |
freakboy3742
left a comment
There was a problem hiding this comment.
Ok - this is an edge case, but it's an edge case worth protecting against. I've made a small tweak to silence a compiler warning, but otherwise the technique seems to work (or work as well as it's ever going to, anyway).
Co-authored-by: Russell Keith-Magee <russell@keith-magee.com>
|
(I assume CI failures are unrelated) |
Two of them were; the last one (pygame) is an issue that was mistakenly introduced into the main branch as a result of trying to get tagged arm64 binaries. I'll merge this as is, and fix the problem in main. Thanks for the PR! |
Console output for GUI apps was not working (confirmed on Windows 11).
Apparently reopening standard descriptors using freopen() after the AttachConsole() call is required.
I just copied this fix from Anki's custom launcher and confirmed it's working: https://github.com/ankitects/anki/blob/81eefc5f7128988a54ff5bb58a6b08697d1214a8/qt/launcher/src/platform/windows.rs#L135
PR Checklist: