[PR #14544] [MERGED] Add support for start /B and FreeConsole #30144

Open
opened 2026-01-31 09:38:53 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/14544
Author: @lhecker
Created: 12/13/2022
Status: Merged
Merged: 12/16/2022
Merged by: @undefined

Base: mainHead: dev/lhecker/14416-freeconsole


📝 Commits (4)

  • bdab6e6 Add support for start /B, FreeConsole
  • b844049 Fix tests, spelling
  • 87a7d93 Fix x86 build, add comments
  • 6a32c28 Address feedback, Fix a race condition

📊 Changes

13 files changed (+271 additions, -158 deletions)

View changed files

📝 .github/actions/spelling/expect/expect.txt (+1 -0)
📝 src/cascadia/TerminalConnection/ConptyConnection.cpp (+54 -74)
📝 src/cascadia/TerminalConnection/ConptyConnection.h (+3 -11)
📝 src/host/PtySignalInputThread.cpp (+2 -2)
📝 src/host/VtIo.cpp (+11 -7)
📝 src/host/VtIo.hpp (+2 -4)
📝 src/host/output.cpp (+0 -3)
📝 src/inc/conpty-static.h (+2 -6)
📝 src/winconpty/dll/winconpty.def (+2 -1)
📝 src/winconpty/ft_pty/ConPtyTests.cpp (+103 -9)
📝 src/winconpty/ft_pty/winconpty.FeatureTests.vcxproj (+4 -0)
📝 src/winconpty/winconpty.cpp (+45 -31)
📝 src/winconpty/winconpty.h (+42 -10)

📄 Description

2 new ConPTY APIs were added as part of this commit:

  • ClosePseudoConsoleTimeout
    Complements ClosePseudoConsole, allowing users to override the INFINITE
    wait for OpenConsole to exit with any arbitrary timeout, including 0.
  • ConptyReleasePseudoConsole
    This releases the \Reference handle held by the HPCON. While it makes
    launching further PTY clients via PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE
    impossible, it does allow conhost/OpenConsole to exit naturally once all
    console clients have disconnected. This makes it unnecessary to having to
    monitor the exit of the spawned shell/application, just to then call
    ClosePseudoConsole, while carefully continuing to read from the output
    pipe. Instead users can now just read from the output pipe until it is
    closed, knowing for sure that no more data will come or clients connect.
    This is especially useful in combination with ClosePseudoConsoleTimeout
    and a timeout of 0, to allow conhost/OpenConsole to exit asynchronously.

These new APIs are used to fix an array of bugs around Windows Terminal exiting
either too early or too late. They also make usage of the ConPTY API simpler in
most situations (when spawning a single application and waiting for it to exit).

Depends on #13882, #14041, #14160, #14282

Closes #4564
Closes #14416
Closes MSFT-42244182

Validation Steps Performed

  • Calling FreeConsole in a handoff'd application closes the tab
  • Create a .bat file containing only start /B cmd.exe.
    If WT stable is the default terminal the tab closes instantly
    With these changes included the tab stays open with a cmd.exe prompt
  • New ConPTY tests

🔄 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/microsoft/terminal/pull/14544 **Author:** [@lhecker](https://github.com/lhecker) **Created:** 12/13/2022 **Status:** ✅ Merged **Merged:** 12/16/2022 **Merged by:** [@undefined](undefined) **Base:** `main` ← **Head:** `dev/lhecker/14416-freeconsole` --- ### 📝 Commits (4) - [`bdab6e6`](https://github.com/microsoft/terminal/commit/bdab6e6777fbfd44c1aedfa69588764e95d4db22) Add support for start /B, FreeConsole - [`b844049`](https://github.com/microsoft/terminal/commit/b844049657d1e5b65b7d73932caed8bc116d333e) Fix tests, spelling - [`87a7d93`](https://github.com/microsoft/terminal/commit/87a7d93ba7e69e2bf6034f9eb8bf0c3899c8f0f3) Fix x86 build, add comments - [`6a32c28`](https://github.com/microsoft/terminal/commit/6a32c2819d92792e37f190fd6bafef1b73a8b75c) Address feedback, Fix a race condition ### 📊 Changes **13 files changed** (+271 additions, -158 deletions) <details> <summary>View changed files</summary> 📝 `.github/actions/spelling/expect/expect.txt` (+1 -0) 📝 `src/cascadia/TerminalConnection/ConptyConnection.cpp` (+54 -74) 📝 `src/cascadia/TerminalConnection/ConptyConnection.h` (+3 -11) 📝 `src/host/PtySignalInputThread.cpp` (+2 -2) 📝 `src/host/VtIo.cpp` (+11 -7) 📝 `src/host/VtIo.hpp` (+2 -4) 📝 `src/host/output.cpp` (+0 -3) 📝 `src/inc/conpty-static.h` (+2 -6) 📝 `src/winconpty/dll/winconpty.def` (+2 -1) 📝 `src/winconpty/ft_pty/ConPtyTests.cpp` (+103 -9) 📝 `src/winconpty/ft_pty/winconpty.FeatureTests.vcxproj` (+4 -0) 📝 `src/winconpty/winconpty.cpp` (+45 -31) 📝 `src/winconpty/winconpty.h` (+42 -10) </details> ### 📄 Description 2 new ConPTY APIs were added as part of this commit: * `ClosePseudoConsoleTimeout` Complements `ClosePseudoConsole`, allowing users to override the `INFINITE` wait for OpenConsole to exit with any arbitrary timeout, including 0. * `ConptyReleasePseudoConsole` This releases the `\Reference` handle held by the `HPCON`. While it makes launching further PTY clients via `PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE` impossible, it does allow conhost/OpenConsole to exit naturally once all console clients have disconnected. This makes it unnecessary to having to monitor the exit of the spawned shell/application, just to then call `ClosePseudoConsole`, while carefully continuing to read from the output pipe. Instead users can now just read from the output pipe until it is closed, knowing for sure that no more data will come or clients connect. This is especially useful in combination with `ClosePseudoConsoleTimeout` and a timeout of 0, to allow conhost/OpenConsole to exit asynchronously. These new APIs are used to fix an array of bugs around Windows Terminal exiting either too early or too late. They also make usage of the ConPTY API simpler in most situations (when spawning a single application and waiting for it to exit). Depends on #13882, #14041, #14160, #14282 Closes #4564 Closes #14416 Closes MSFT-42244182 ## Validation Steps Performed * Calling `FreeConsole` in a handoff'd application closes the tab ✅ * Create a .bat file containing only `start /B cmd.exe`. If WT stable is the default terminal the tab closes instantly ✅ With these changes included the tab stays open with a cmd.exe prompt ✅ * New ConPTY tests ✅ --- <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-31 09:38:53 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#30144