Skip to content

Fix console output for GUI apps#88

Merged
freakboy3742 merged 3 commits into
beeware:mainfrom
ankitects:console
Apr 19, 2026
Merged

Fix console output for GUI apps#88
freakboy3742 merged 3 commits into
beeware:mainfrom
ankitects:console

Conversation

@abdnh
Copy link
Copy Markdown
Contributor

@abdnh abdnh commented Apr 14, 2026

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:

  • All new features have been tested
  • All new features have been documented
  • I have read the CONTRIBUTING.md file
  • I will abide by the code of conduct

@freakboy3742
Copy link
Copy Markdown
Member

Can you clarify what you mean by "not working"? What's the reproduction case for this problem?

@abdnh
Copy link
Copy Markdown
Contributor Author

abdnh commented Apr 14, 2026

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:

  1. Run briefcase create && briefcase package.
  2. Open a Powershell console and run the executable: & '.\Hello World.exe'
  3. Notice no output.

abdnh added a commit to ankitects/anki that referenced this pull request Apr 14, 2026
## 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
@freakboy3742
Copy link
Copy Markdown
Member

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:

  1. Run briefcase create && briefcase package.
  2. Open a Powershell console and run the executable: & '.\Hello World.exe'
  3. Notice no output.

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?

@abdnh
Copy link
Copy Markdown
Contributor Author

abdnh commented Apr 16, 2026

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.

Copy link
Copy Markdown
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Comment thread {{ cookiecutter.format }}/{{ cookiecutter.formal_name }}/Main.cpp Outdated
abdnh and others added 2 commits April 17, 2026 16:07
Co-authored-by: Russell Keith-Magee <russell@keith-magee.com>
@abdnh
Copy link
Copy Markdown
Contributor Author

abdnh commented Apr 17, 2026

(I assume CI failures are unrelated)

@freakboy3742
Copy link
Copy Markdown
Member

(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!

@freakboy3742 freakboy3742 merged commit c188965 into beeware:main Apr 19, 2026
36 of 40 checks passed
@abdnh abdnh deleted the console branch April 19, 2026 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants