[PR #1394] [MERGED] Console: Fix problems when using CLI from MSYS2/GitBash/ConEmu #490

Open
opened 2026-01-29 19:08:09 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/stenzek/duckstation/pull/1394
Author: @jstine35
Created: 1/5/2021
Status: Merged
Merged: 1/8/2021
Merged by: @stenzek

Base: masterHead: msw_console_behavior


📝 Commits (2)

  • c9b8dc1 Console: Fix problems when using CLI from MSYS2/GitBash/ConEmu
  • f26b094 Console: Use ANSI escape codes and remove entirely Win32's legacy WriteConsoleA code.

📊 Changes

1 file changed (+186 additions, -131 deletions)

View changed files

📝 src/common/log.cpp (+186 -131)

📄 Description

what it does

  • Fix issue where console output is lost when running from MSYS2/GitBash CLI
  • Fix issue where pipe redirections would be overridden and output would always go to the attached console (this affected windows cmd prompt as well as other shell CLIs)
  • Simplifies some logic regarding registering of the standard output writer
  • A best-effort is made to honor any pre-existing pipe redirections which may have been specified by user or an invoking process.

test cases

  • run from GitBash/mintty and observe that help printed to the terminal:
$ duckstation -help
  • run from explorer/Visual Studio and observe that console window is allocated when Console is enabled.

remarks about standard outputs

I renamed some of the ConsoleOutput functions to StandardOutput, though only ones static to the scope of log.cpp for now. The terminology clarity can be helpful. The Console is very much a Microsoft Windows (MSW) term and is rarely used outside of the Windows ecosystem. Better terms are as follows:

  • Terminal (TTY) : this defines a window or socket/device that can receive Standard Output and provide Standard Input
  • Shell (Command Processor) : this defines an application that can receive Standard Input and execute commands, scripts, etc. and usually ensures any processes it creates have their standard pipes attached to the terminal (unless redirected).

When you combine a Terminal with a Shell, you get an interactive Command Prompt we all know. You can run shells without the terminal, and you can run terminals without a shell. Windows Console is a terminal without a shell. Windows Terminal (the new UWP replacement for Console available on the Windows App Store) is also a terminal without a shell.

Anyway, whether it's a terminal or console isn't important. What is important is that it's writing to "standard output" -- this is a construct that can, at the discretion of the invoking user or process, be either:

  • a terminal/console
  • a redirection to a file
  • a redirection to another process
  • a redirection to a socket or FIFO that can then be read asynchronously by other shells and processes (my favorite!)

This was all part of the rationale for me renaming 'ConsoleOutput' to 'StandardOutput'

WIN32 vs. _WIN32

I used _WIN32 to identify the Windows SDK platform. I consider the define preferable as it's a first-class buildsystem define, similar to _MSC_VER / __clang__ / __ANDROID__, etc. and such. By comparison, WIN32 must be manually specified by the makefile/vcxproj. In many newer project templates, I've seen the define missing entirely. My recommendation is to migrate all your instances of WIN32 to _WIN32 at some point.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/stenzek/duckstation/pull/1394 **Author:** [@jstine35](https://github.com/jstine35) **Created:** 1/5/2021 **Status:** ✅ Merged **Merged:** 1/8/2021 **Merged by:** [@stenzek](https://github.com/stenzek) **Base:** `master` ← **Head:** `msw_console_behavior` --- ### 📝 Commits (2) - [`c9b8dc1`](https://github.com/stenzek/duckstation/commit/c9b8dc13fd53b24fb688bcc118ea0d400207a581) Console: Fix problems when using CLI from MSYS2/GitBash/ConEmu - [`f26b094`](https://github.com/stenzek/duckstation/commit/f26b094cf75a2c2aa24deb45d60c8e4e49f442d7) Console: Use ANSI escape codes and remove entirely Win32's legacy WriteConsoleA code. ### 📊 Changes **1 file changed** (+186 additions, -131 deletions) <details> <summary>View changed files</summary> 📝 `src/common/log.cpp` (+186 -131) </details> ### 📄 Description ## what it does - Fix issue where console output is lost when running from MSYS2/GitBash CLI - Fix issue where pipe redirections would be overridden and output would always go to the attached console (this affected windows cmd prompt as well as other shell CLIs) - Simplifies some logic regarding registering of the standard output writer - A best-effort is made to honor any pre-existing pipe redirections which may have been specified by user or an invoking process. ## test cases - run from GitBash/mintty and observe that help printed to the terminal: ``` $ duckstation -help ``` - run from explorer/Visual Studio and observe that console window is allocated when Console is enabled. ## remarks about standard outputs I renamed some of the `ConsoleOutput` functions to `StandardOutput`, though only ones static to the scope of `log.cpp` for now. The terminology clarity can be helpful. The Console is very much a Microsoft Windows (MSW) term and is rarely used outside of the Windows ecosystem. Better terms are as follows: - Terminal (TTY) : this defines a window or socket/device that can receive Standard Output and provide Standard Input - Shell (Command Processor) : this defines an application that can receive Standard Input and execute commands, scripts, etc. and usually ensures any processes it creates have their standard pipes attached to the terminal (unless redirected). When you combine a Terminal with a Shell, you get an interactive Command Prompt we all know. You can run shells without the terminal, and you can run terminals without a shell. Windows Console is a terminal without a shell. Windows Terminal (the new UWP replacement for Console available on the Windows App Store) is also a terminal without a shell. Anyway, whether it's a terminal or console isn't important. What is important is that it's writing to "standard output" -- this is a construct that can, at the discretion of the invoking user or process, be either: - a terminal/console - a redirection to a file - a redirection to another process - a redirection to a socket or FIFO that can then be read asynchronously by other shells and processes (my favorite!) This was all part of the rationale for me renaming 'ConsoleOutput' to 'StandardOutput' ### `WIN32` vs. `_WIN32` I used `_WIN32` to identify the Windows SDK platform. I consider the define preferable as it's a first-class buildsystem define, similar to `_MSC_VER` / `__clang__` / `__ANDROID__`, etc. and such. By comparison, `WIN32` must be manually specified by the makefile/vcxproj. In many newer project templates, I've seen the define missing entirely. My recommendation is to migrate all your instances of `WIN32` to `_WIN32` at some point. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-29 19:08:09 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/duckstation#490