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

[Windows] Improve console IO redirection. #91147

Merged
merged 1 commit into from
Apr 29, 2024

Conversation

bruvzg
Copy link
Member

@bruvzg bruvzg commented Apr 25, 2024

Improves console IO redirection and Unicode handling.

Operation Console Wrapper subsystem=windows subsystem=console Comments
Godot print to console
Godot print to file/pipe Rich print write escape sequences to the file.
Godot get_stdin_string from console Hangs waiting for input, probably not fixable.
Godot get_stdin_string from file/pipe
C printf/std::cout to console
C printf/std::cout to file/pipe
C printf/std::cout in GDExtension to console Tested both MinGW and MSVC
C printf/std::cout in GDExtension to file/pipe
C# Console.WriteLine to console
C# Console.WriteLine to file/pipe
C# GD.Print to console
C# GD.Print to file/pipe

Unicode characters seems to be working in all tested cases (both input and output), IO redirected to/from file/pipe expect and write text as UTF-8 without BOM (same as other platforms).

Note: using > to redirect in PowerShell seems to be broken (not sure if it supposed to work), but Start-Process ... -RedirectStandardOutput works fine. In cmd > and < works fine.

Fixes #87591
Fixes #91002

@akien-mga
Copy link
Member

CC @hhyyrylainen

@hhyyrylainen
Copy link

hhyyrylainen commented Apr 26, 2024

So I didn't manage to export my game with this branch because I couldn't get the compiled mono assemblies to match up (presumably I would need to setup that local nuget repo that the docs mention, or somehow force the built Godot editor to use the dev.5 sdk version suffix), but I did get so far as to see that my game now outputs ERROR: Mono Cache: Managed callback for 'DisposablesTracker_OnGodotShuttingDown' is null. which if it is triggered after the redirection is setup, would mean that these changes work for my use case.

@Calinou
Copy link
Member

Calinou commented Apr 26, 2024

Rich print write escape sequences to the file.

#90900 could be applied to stdout and stderr if non-TTY output is detected, or when the --color never or NO_COLOR=1 environment variable is used, like I did in #77261.

@bruvzg bruvzg marked this pull request as ready for review April 27, 2024 21:36
@bruvzg bruvzg requested a review from a team as a code owner April 27, 2024 21:36
Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

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

Looks good. Thanks for the overview of what works for each build type.

Do we still need the console wrapper after all this? If things like printing normal output to the host terminal works fine with the normal windows subsystem build, I feel like the console.exe might not add much value (but does add confusion for users on what it's for and whether to ship it).

@akien-mga akien-mga modified the milestones: 4.x, 4.3 Apr 29, 2024
@akien-mga akien-mga merged commit 271d7c8 into godotengine:master Apr 29, 2024
16 checks passed
@akien-mga
Copy link
Member

Thanks!

@bruvzg
Copy link
Member Author

bruvzg commented Apr 29, 2024

Do we still need the console wrapper after all this?

I would keep it since it's still a more convenient way to start the editor with console output from the UI. As well as providing a bit more consistent behavior than windows subsystem binary when using from console and scripting (shell will properly wait for all spawned precesses, and won't show command prompt in the middle of output if you input something). Also, the only way to get input from console working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants